Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON TEXT / CHAPTER 03 / Learn / LESSON 04
Fourth class. You often want to mix text and values in one message.
An f-string starts with f before the quotes. Inside {} you put an expression: f"{name} scored {score}". The expression is evaluated and inserted as text.
You can compute inside: f"next: {score + 1}". That is clearer than concatenating with + and str().
Mini example:
name = "Ada"
n = 10
print(f"{name} has {n}")
print(f"next {n + 1}")Common mistake: forgetting the f before the quotes — then {name} prints literally; or adding unnecessary quotes inside {}.
Learn: an f-string inserts expressions inside {}.
LAUNCH STANDBY
›