Expressions are recipes for a single value
An expression is anything Python can compute down to a single value. These are all expressions:
3 + 4 # arithmetic
"hi" + "!" # string concatenation
10 / 4 # division -> 2.5
10 // 4 # integer (floor) division -> 2
10 % 4 # remainder (modulo) -> 2
2 ** 8 # exponent (2 to the 8th) -> 256
Python evaluates expressions following standard precedence: parentheses, exponents, then multiplication/division/modulo, then addition/subtraction, left to right within the same level.
input() asks the user for a line of text
name = input("What is your name? ")
print("Hello,", name)
The thing input() returns is always a string — even if the user types digits. To do math on it, convert with int(...) or float(...):
raw = input("How old are you? ")
age = int(raw)
next_age = age + 1
print("Next year you will be", next_age)
Type conversion can fail
int("12") → 12 (works)int("twelve") → raises ValueErrorint("12.5") → raises ValueError (use float first if there's a decimal)"hi" + 5 → raises TypeError (can't add a string and an int)
Putting numbers back into a line of text
Going the other direction is just as common. print() takes several values separated by commas, but it puts a space between each one:
hours = 2
mins = 25
print(hours, "h", mins, "m") # 2 h 25 m <- spaces you did not ask for
When the pieces need to sit together with no gaps, you have two ways:
str(hours) + "h" gives 2h. str(...) turns a number into text so + can join it to other text. That is the answer to the "hi" + 5 problem above: convert first, then join.f"{hours}h {mins}m" gives 2h 25m. This is an f-string: put an f before the opening quote, and anything you write inside { } is worked out and dropped into the line.
The f-string is the one you will see most often, and it is the shortest way to build a line out of several values.
Predict-then-run. Before clicking Run on the editor below, write down what the program would print on a piece of paper. Then run it and compare.