Lesson 12 of 40Article14 min
String Formatting & None
f-strings are the modern default: f"{name} scored {score}". .format() and % formatting still appear in older code.
Python String Formatting
f-strings are the modern default: f"{name} scored {score}". .format() and % formatting still appear in older code.
Format numbers: f"{price:.2f}", f"{n:,}" for thousands separators.
Real-life example: String formatting is filling a form letter — same sentence, different names each time.
f-string formatting
name, score = "Riya", 92.567
print(f"{name} scored {score:.1f}%")
print("{} scored {:.1f}%".format(name, score))Python None
None means no value or missing data. Functions without return implicitly return None.
Check with is None — not == None. Optional parameters often default to None.
Real-life example: None is an empty chair — the seat exists but nobody is sitting there yet.
None checks
result = None
def find_user(id):
return None # not found
user = find_user(99)
if user is None:
print("User not found")