appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Values, variables and printing

Lesson 1 of 49 minBeginner

Numbers, text, booleans, and how to store and show them.

Python reads your code line by line. Save a file as hello.py and run it with python3 hello.py, or type python3 alone to try lines interactively.

print("Hello, world")
name = "Ana"
age = 31
print(name, "is", age)

Variables and types

A variable is a name that points to a value. You do not declare its type: Python works it out.

TypeExampleNotes
int42Whole numbers, any size
float3.14Decimal numbers
str"text"Text, single or double quotes
boolTrue, FalseCapital first letter
NoneNoneMeans "no value"

Operators

7 + 2     # 9
7 / 2     # 3.5 (division always gives a float)
7 // 2    # 3   (floor division)
7 % 2     # 1   (remainder)
2 ** 10   # 1024 (power)

Text with f-strings

price = 19.5
print(f"Total: ${price * 2:.2f}")   # Total: $39.00

NoteUse type(x) to see a value's type and input("Your name: ") to read text typed by the user. input always returns a string.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. What does 7 // 2 give in Python?
2. What is the type of "42" (with quotes)?
Hintprint( ... ) with the text in quotes.
4. What does 2 ** 3 equal?

Key terms