I am a line of Python code
I make numbers look pretty with commas and ₦
But mess up one f-string curly brace and… chaos
What line am I?
#Python#CodingJourney#PythonStrings
String power: Used .translate() with str.maketrans to remove punctuation: clean_text = desc.translate(str.maketrans("", "", string.punctuation)).strip(). Then split into words. Great for search normalization. #PythonStrings#PythonTips
String format deep dive: f-strings with expressions: f"Total: ₦{base_price * nights:,} ({nights} nights)" – formatted with commas. .zfill(2) on day strings for "01". Formatting output key for user-friendliness. #PythonStrings#PythonTips
String deep dive: Used .find() and slicing: desc = "Deluxe room with king bed". if "king" in desc.lower(): room_type = desc[desc.find("king"):desc.find("bed")+3].strip() → "king bed". Parsing messy text! #PythonStrings#PythonTips#CodingJourney
String combo today: Used .replace() and .split() to clean input: raw = " iris-inn , deluxe ".strip().replace("-", " ").split(",") → cleaned = [s.strip().title() for s in raw] → ["Iris Inn", "Deluxe"]. Input handling smoother. #PythonStrings#PythonTips
String power move: Used .split() and .join() to clean user input: user_search = " iris inn ".strip().lower().split() → clean = " ".join(user_search).title() → "Iris Inn". Checked if clean in hotels. Super useful for search! #PythonStrings#PythonTips
String warm-up: Used .upper(), .lower(), .strip(), f-strings to format hotel names: clean_name = hotel["name"].strip().title() → "Iris Comfort". Printed f"Welcome to {clean_name} – only ₦{hotel['price']:,}!". Clean output in seconds. #PythonStrings#PythonTips
4/ Strings (str) 📝
Used for text data:
name = "Alice"
greeting = 'Hello, World!'
print(type(name)) # Output: <class 'str'>
Strings support concatenation & formatting:
full_name = name + " Smith"
print(full_name) # Output: Alice Smith
#PythonStrings#Coding