Mastering Python Strings with Indexing & f-strings

Just wrapped up strings in Python! Today I practiced: • Indexing & slicing • Common string methods (.upper(), .replace(), .count(), etc.) • f-strings ( way to format strings) Here’s code from a few exercises: python # String practice text = 'Hello, welcome to Python programming!' print(text.upper()) print(text.count('o')) print(text.find('Python')) new_text = text.replace('Python', 'the world of coding') print(new_text) # f-string example item = 'book' price = 19.99 quantity = 3 print(f"I bought {quantity} {item}s for ${price * quantity:.2f}") Output: HELLO, WELCOME TO PYTHON PROGRAMMING! 4 18 Hello, welcome to the world of coding programming! I bought 3 books for $59.97 Shoutout to Corey Schafer’s crystal-clear tutorial that inspired these exercises: https://lnkd.in/dvzNwUmM #Python

To view or add a comment, sign in

Explore content categories