Mastering Python String Methods & f-strings helps you write clean and reliable Python code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
Python String Methods & f-strings Code Example
Python
text = " learn python at codesintech "
clean = text.strip()
print(clean.title())
print(clean.upper())
print(clean.replace("python", "SQL"))
print(clean.split(" "))
print("-".join(["2026", "10", "22"]))
print(clean.count("o"), clean.startswith("learn"))
name, price, users = "Course", 4999.5, 1250000
print(f"{name} costs Rs {price:.2f} and has {users:,} users")
Free sign-in required · Google login available
Python String Methods & f-strings Practice Exercises
Check what you learned in “Python String Methods & f-strings”.
/ 3 solved
Fill in the blank
Create an f-string.
"Hello {name}"
✓ Correct!Not quite. Try again.
Multiple choice
Which method splits "a,b,c" into a list?
✓ Correct!Not quite. Try again.
Code challenge
Use an f-string to print "Ali is 30 years old".
Write the code in the live editor. Your answer is checked automatically.