Variables and Data Types

Variables and Data Types

You do not declare types; Python infers them. Variables are created by assignment.

Basic types

python
age = 25 price = 19.99 name = \"Froquiz\" active = True
  • int – integers (arbitrary precision in Python 3).
  • float – decimals.
  • str – text in double or single quotes.
  • boolTrue or False.

Strings

Concatenate with +, repeat with *:

python
greeting = \"Hello, \" + name line = \"=\" * 40

F-strings (Python 3.6+) for formatting:

python
msg = f\"User {name} is {age} years old\"

Type hints (optional)

You can annotate types for clarity and tooling:

python
def add(a: int, b: int) -> int: return a + b

Constants

By convention, UPPER_SNAKE_CASE for constants. Nothing prevents reassignment; it is convention only.