Variables
A variable is a symbolic name that represents and refers to a value.
It allows you to label data with a descriptive name, making it easier to understand and manipulate.
Pythonage = 25 # 'age' is a variable storing the value 25
name = "John" # 'name' is a variable storing the string "John"
Assignments
Assigning a value to a variable is done using the = operator.
The variable takes on the type of the assigned value dynamically.
Pythonx = 10 # 'x' is assigned the value 10
y = "Hello" # 'y' is assigned the string "Hello"
Multiple Assignments
You can assign values to multiple variables in a single line.
Pythona, b, c = 1, 2, 3 # 'a' is 1, 'b' is 2, 'c' is 3
Variable Naming Rules
Variable names must start with a letter (a-z, A-Z) or an underscore (_)
The rest of the name can include letters, numbers, and underscores
Choose meaningful and descriptive names to enhance code readability
Python_my_var = 42 # Variable name starts with an underscore
Dynamic Typing
Python is dynamically typed, meaning you don't explicitly declare the data type of a variable.
The interpreter dynamically determines the type based on the assigned value.
Pythondynamic_var = 3.14 # 'dynamic_var' is dynamically assigned the float type
Variable Reassignment
Variables can be reassigned to new values, even of a different type.
Pythoncount = 5
count = "Hello" # Reassigning 'count' to a new value with new type (string)