Lecture
Case Conversion Methods upper() and lower()
How can you convert the string "apple" to "APPLE" or "APPLE" to "apple" in one step?
Python provides the upper() and lower() methods to change the case of characters in a string.
Using Case Conversion Methods
The upper() method converts all characters in a string to uppercase, and the lower() method converts them to lowercase.
Case Conversion Example
text = "Hello World!" upper_text = text.upper() # HELLO WORLD! print("upper_text:", upper_text) lower_text = text.lower() # hello world! print("lower_text:", lower_text)
When is Case Conversion Needed?
In programming, case conversion is mainly used during normalization, where user input is transformed into a consistent, standard format.
What is Normalization? : Normalization is the process of converting data into a consistent format. Common tasks include transforming all text to lowercase or removing spaces to facilitate comparison.
Data Normalization Example
user_input = "PyThOn" standardized_input = user_input.lower() if standardized_input == "python": print("Matched!") else: print("Not Matched.")
Previous lessonMultiple-choice quizNext lessonRemoving Leading and Trailing Whitespace with the strip() Function
Lessons in this chapter · String Formatting Made Easy
- 1. Inserting Variables into Strings with the format() Function
- 2. Tips for Using `format()` Function - indexError
- 3. Displaying Integers with the format() Function
- 4. Handling Floating-Point Numbers with the format() Function
- 5. Multiple-choice quiz
- 6. Case Conversion Methods upper() and lower()
- 7. Removing Leading and Trailing Whitespace with the strip() Function
- 8. String Composition Verification with isOOO() Methods
- 9. Finding the Position of a Specific Character Using find() and rfind()
- 10. Using the split() Method for Strings
- 11. How to Check if a Specific Character Exists in a String
- 12. Multiple-choice quiz
- 13. How to Format Strings with f-Strings
- 14. Comparison of format() Function and f-Strings
- 15. Using the `input` Function to Receive User Input
- 16. Indicating Invalid Values with ValueError
- 17. Coding Quiz - Splitting Strings
- 18. Multiple-choice quiz
- 19. Fill-in-the-blank quiz
Quiz
0 / 1
What function in Python converts all characters of a string to uppercase?
capitalize()
title()
upper()
lower()
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help