DEV Community

Cover image for Upper() and Lower() - Manually -NLP
datatoinfinity
datatoinfinity

Posted on • Edited on

Upper() and Lower() - Manually -NLP

What is lower() in python?

lower() is built-in function which is used to convert uppercase character to lowercase character. If character is passed already in lowercase then it will remain same.

What is upper() in python?

upper() is built-in function which is used to convert lowercase character to uppercase character. If character is passed already in uppercase then it will remain same.

text1="hey how are you? how it is going?"
text2="IT'S GOING GREAT."
print("Converting it into Upper ",text1.upper())
print("Converting it into Lower ",text2.lower())
Output:
Converting it into Upper  HEY HOW ARE YOU? HOW IT IS GOING?
Converting it into Lower  it's going great.

Now we did it manually:

def upper(text):
    string=''
    for char in text:
        if ord(char)>=97 and ord(char)<=122:
            string+=chr(ord(char)-32)
        else:
            string+=char
            
    return string
    
def lower(text):
    string=''
    for char in text:
        if ord(char)>=65 and ord(char)<=90:
            string+=chr(ord(char)+32)
        else:
            string+=char
            
    return string
    
print(upper('delhi'))
print(lower('HELLO'))
DELHI
hello

Top comments (1)

Collapse
 
therahul_gupta profile image
Rahul Gupta

Thanks for sharing.