Lowercase conversion changes every letter in a string to lowercase. In Python, use dot notation: write the string or string variable, then .lower(). Numbers and special characters stay unchanged. section 7.3 section 7.0
Convert text to lowercase
"Ups AND Downs".lower() evaluates to "ups and downs". The dot connects the string to an operation designed for string objects. For example, a = "Python 4 EVER" followed by a.lower() produces "python 4 ever". section 7.3
Related case operations change letters in different ways:
- upper() changes all letters to uppercase. section 7.3
- swapcase() exchanges lowercase and uppercase letters. section 7.3
- capitalize() makes the first character uppercase and the remaining letters lowercase. section 7.3
- Combining .lower() with concatenation helps format generated names consistently. section 12.4
Listing 12.4. Combining the names
newname1_first = lefthalf_name1_first.capitalize() + \ #1
righthalf_name2_first.lower() #2
newname1_last = lefthalf_name1_last.capitalize() + \
righthalf_name2_last.lower()
newname2_first = lefthalf_name2_first.capitalize() + \
righthalf_name1_first.lower()
newname2_last = lefthalf_name2_last.capitalize() + \
righthalf_name1_last.lower()
print("All done! Here are two possibilities, pick the one you like best!")
print(newname1_first, newname1_last) #3
print(newname2_first, newname2_last) #3
A name-mashup listing shows .lower() formatting one half of each generated name before printing the results. section 12.4
