liveBook · Manning

Lowercase

As explained in Get Programming: Learn to code with Python

Lowercase conversion is the transformation of alphabetic text so that its letters are represented in lowercase form.

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

How Get Programming: Learn to code with Python covers it

How deep it goes
Defines .lower(), demonstrates its result, and stops short of deeper string-processing internals.
Examples
Uses "Ups AND Downs", essay text, a mixed-case variable, and generated names as concrete examples.
What it assumes
Assumes basic string values and teaches the string-specific dot notation needed to call .lower().
What you can do after
Apply lowercase conversion via Python's .lower() operation to format and normalize string values.
How it connects
Connects lowercase conversion with strings, dot notation, upper(), swapcase(), capitalize(), and concatenation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.