A variable in Python is used to store data that can be referenced and manipulated throughout your code. You donβt need to declare the data type β Python does it automatically.
name = "Alice" age = 25 is_active = True
Age
and age
are different)# Valid variables username = "admin" _user = "hidden" score123 = 100 # Invalid (will cause error) 123score = 50 # β starts with a number user-name = "X" # β hyphen not allowed
You can change the value and even the data type of a variable anytime.
x = 10 print(x) # 10 x = "Python" print(x) # Python
# Multiple variables, multiple values a, b, c = 1, 2, 3 # One value to multiple variables x = y = z = "Hello"
user_age
instead of x
, especially in real projects.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!