Python Data Containers
Last updated:
Variables
Store values in a program:
name = "Alice"
age = 30
a, b, c = 1, 2, 3
The variable data types doesn’t need to explicitly be defined when declaring it:
x = 42 # x is an integer
x = "Hello" # x is now a string
x = 3.14 # x is now a float
- dynamically-typed - Python is a dynamically-typed language - the interpreter infers the data type automatically based on the value assigned to the variable
- No variable scope keywords
- Automatic memory management - memory allocation and deallocation for variables is handled automatically.
- Multiple assignment - assign values to multiple variables simultaneously in a single line.
- Immutable basic types - Some basic data types like strings, integers, and tuples are immutable. This means that once a value is assigned to a variable of these types, you cannot change the value directly. However, you can reassign the variable to a new value.
Naming conventions
- must start with a letter (a-z, A-Z) or an underscore (_), followed by letters, numbers (0-9), or underscores
- are case-sensitive
- recommended to use lowercase with words separated by underscores (snake_case) for readability