Python Python Trim String Example

Python upper(), lower(), isupper(), and islower() Methods example


Sometimes we may need to Convert String characters to uppercase and lowercase, for this purpose Python provides us two methods:

  • The upper() string method converts all of the characters to uppercase
  • The lower() string method converts all of the characters to lowercase

upper() string method example

code

code = 'Codesource.io'
code.upper()
print(f'After converting to uppercase =\'{code.upper()}\'')

output

After converting to uppercase ='CODESOURCE.IO'

lower() string method example

code

code = 'Codesource.io'
code.lower()
print(f'After converting to lowercase =\'{code.lower()}\'')

output

After converting to lowercase ='code-source.tempurl.host'

isupper(), and islower() Methods

  • The isupper() method will return a Boolean True value if the string has one or more letters & all the letters are uppercase
  • The islower() method will return a Boolean True value if the string has one or letters & all the letters are lowercase

isupper() method example

code

code = 'CODESOURCE.IO'
code.isupper()
print(f'if string has all the uppercase letters =\'{code.isupper()}\'')

output

if string has all the uppercase letters ='True'

islower() method example

code

code = 'Codesource.io'
code.islower()
print(f'if string has all the lowercase letters =\'{code.islower()}\'')

output

if string has all the lowercase letters ='False'

Share on social media

//