Test your Python skills with Coding Exercises on string methods and formatting. Great for beginners learning Python strings through hands-on practice.
Ask the user for their name and print: - The name in all uppercase - The name in all lowercase - The number of characters in the name
name = input("Enter your name: ")
Uppercase: JOHN
Lowercase: john
Length: 4
Given a string with leading and trailing spaces, remove them and print the cleaned sentence.
sentence = " Python is fun! "
Cleaned Sentence: Python is fun!
Align the word "Code" within a 20-character width using different alignments.
word = "Code"
Centered : Code
Left : Code
Right : Code
Perform slicing on the string "Python Programming": - Extract and print the first 6 characters - Extract and print the last 11 characters - Extract and print characters from index 7 to 17
text = "Python Programming"
First 6 characters: Python
Last 11 characters: Programming
Characters 7 to 17: Programming
Given name and age variables, print: "My name is Alice and I am 30 years old."
name = "Alice"
age = 30
My name is Alice and I am 30 years old.