Last Updated on 2021-12-11 by Clay
Using Python to process the case conversion of strings, or the comparison of upper and lower case strings is an extraordinarily easy task. First, Python is a simple and easy-to-write programming language. Second, these commonly used capitalization conversion methods have long been built into Python's string processing.
Today, I will record the following different Python string case processing:
- Determine case
- Convert case
Determine case
islower()
: Determine whether the string is all lowercaseisupper()
: Determine whether the string is all uppercaseistitle()
: Determine whether the string conforms to the title format (the first letter is capitalized)
a = "lower"
b = "UPPER"
c = "This Is A Title"
print(a.islower())
print(b.isupper())
print(c.istitle())
Output:
True
True
True
Convert case
lower()
: Convert all characters in the string to lowercase lettersupper()
: Convert all characters in the string to uppercase letterscapitalize()
: Convert the first letter to uppercase and the others to lowercasetitle()
: Convert the first letter of each word to uppercase, the others are lowercase
s = "there is a BIG news!"
print("lower():", s.lower())
print("upper():", s.upper())
print("capitalize():", s.capitalize())
print("title():", s.title())
Output:
lower(): there is a big news!
upper(): THERE IS A BIG NEWS!
capitalize(): There is a big news!
title(): There Is A Big News!
References
- https://thehelloworldprogram.com/python/python-string-methods/
- https://www.geeksforgeeks.org/isupper-islower-lower-upper-python-applications/
- https://www.programiz.com/python-programming/methods/string/lower