Day 3: String Manipulation

Ask the user for a word. Print the word in uppercase, lowercase, and its length. (Concepts: string methods .upper(), .lower(), len())

Sample Code:

word = input("Enter a word: ")
print("Uppercase:", word.upper())
print("Lowercase:", word.lower())
print("Length:", len(word))

Students, Day 3 is about strings—text data in Python, always in quotes. We grab a word with input() and store it in word. Strings have built-in methods (like functions attached to them) for manipulation.

First, word.upper() converts every letter to uppercase—it doesn't change the original word, just returns a new version. Similarly, word.lower() makes it all lowercase. These are called with a dot after the variable. Then, len(word) isn't a method but a function that counts characters, including spaces if any (though we said "word," try a phrase!).

In print(), we label each and show the result. Enter "Python"—outputs Uppercase: PYTHON, Lowercase: python, Length: 6. Spend your time: What if you chain methods, like word.upper().lower()? (It'd be lowercase.) Or try other methods like .title() for capitalization. This shows strings are objects with tools—fun for text games later!

Leave a Comment

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

Scroll to Top