0
Ord,lower,upper,is lower,is upper,....
Hello.how to recognize if a letter is small or large in a string without using ord or commands like upper and lower? I want to convert a sentence like this: hsiW You ereW ereH To this: Wish You Were Here Without using those commands.
7 Answers
+ 9
Marjaf ,
(first of all upper() and lower() are not commands but methods of the string class)
lo_ltr = "abcdefghijklmnopqrstuvwxyz"
# iterate through the input string with a for loop
# then check if the letter is in lo_ltr. if True, letter is lower, if False, letter is upper
+ 5
U can check via ASCII value small letter and capital letters have different different ascii range u can use them
+ 5
Marjaf exactly you have use if condition with for loop if you characters will be match then u can return true or false or give whatever u want
+ 4
if 'a' <= letter <= 'z': # check if letter is lowercase
....
Or
import string
if letter in string.ascii_lowercase:
....
Works same for uppercase.
+ 3
There is islower() and isupper() methods from class `str` that you can use to check whether a string/char was of lower or upper case.
+ 1
Inactive unfortunately I can't use ASCII Code.
+ 1
Try the .title() function..
C = "some text"
Print(c.title())
#Output Some Text