How to Change Python String Cases?

python string lowercase and uppercase

To convert a Python string to lowercase/uppercase, use the built-in methods lower() and upper().

For example:

"Hello, world".upper() # HELLO WORLD
"HELLO, WORLD".lower() # hello world

Find out other case conversions in Python below:

Check If a String Is in Lowercase/Uppercase

If you want to test if a string is in uppercase or lowercase, use the built-in isupper() and islower() methods:

For example:

"Hello, world".islower() # False
"HELLO, WORLD".isupper() # True

How to Capitalize the First Letter of a String in Python

If you want to capitalize the first letter, use the built-in capitalize() method.

For example:

"hello, world".capitalize() # Hello, world

How to Swap Cases in Python

To make lowercase letters to upper and uppercase letters to lower, use the swapcase() method.

For example:

"HELLO, world".swapcase() # hello, WORLD

How to Title Case a String in Python

To capitalize the first letter of each word in a string, use the title case converter by calling title() method.

For example:

"hello, world".title() # Hello, World


Thanks for reading. Happy coding!

Further Reading

50 Python Interview Questions and Answers

50+ Buzzwords of Web Development

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest

Leave a Comment

Your email address will not be published. Required fields are marked *