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.

27th Nov 2021, 10:31 AM
Marjaf
Marjaf - avatar
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
27th Nov 2021, 10:42 AM
Lothar
Lothar - avatar
+ 5
U can check via ASCII value small letter and capital letters have different different ascii range u can use them
27th Nov 2021, 10:36 AM
đŸ’«AsđŸ’«
đŸ’«AsđŸ’« - avatar
+ 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
27th Nov 2021, 10:45 AM
đŸ’«AsđŸ’«
đŸ’«AsđŸ’« - avatar
+ 4
if 'a' <= letter <= 'z': # check if letter is lowercase .... Or import string if letter in string.ascii_lowercase: .... Works same for uppercase.
27th Nov 2021, 10:44 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
27th Nov 2021, 11:03 AM
Ipang
+ 1
Inactive unfortunately I can't use ASCII Code.
27th Nov 2021, 10:38 AM
Marjaf
Marjaf - avatar
+ 1
Try the .title() function.. C = "some text" Print(c.title()) #Output Some Text
27th Nov 2021, 11:39 AM
Ramprasad
Ramprasad - avatar