f-strings
Drop variables straight into text, the modern Python way.
1name = "Ada"
2age = 10
3print(f"{name} is {age} years old")
$ python3 main.py
Ada is 10 years old
Every line, explained
name = "Ada"- This creates a variable: a named box that stores a value. In Python you just write name = value: the = stores the value on the right into the name on the left. No special type word, no semicolon; Python keeps it simple.
age = 10- This creates a variable: a named box that stores a value. In Python you just write name = value: the = stores the value on the right into the name on the left. No special type word, no semicolon; Python keeps it simple.
print(f"{name} is {age} years old")- The f right before the opening quote makes this an f-string. Inside an f-string, curly braces are magic: Python swaps {name} for the value of the variable name. This is the modern Python way to mix variables into text. Here {name} becomes Ada and {age} becomes 10. Much tidier than gluing pieces together with +!