PYTHON Tutorial



VARIABLES IN PYTHON


πŸ“¦ Variables in Python

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.

βœ… How to Create Variables

name = "Alice"
age = 25
is_active = True
  

πŸ” Variable Naming Rules

  • Must start with a letter or underscore (_)
  • Cannot start with a number
  • Can contain letters, numbers, and underscores
  • Are case-sensitive (e.g., Age and age are different)

πŸ§ͺ Example

# Valid variables
username = "admin"
_user = "hidden"
score123 = 100

# Invalid (will cause error)
123score = 50     # ❌ starts with a number
user-name = "X"   # ❌ hyphen not allowed
  

πŸ”„ Reassigning Variables

You can change the value and even the data type of a variable anytime.

x = 10
print(x)       # 10

x = "Python"
print(x)       # Python
  

πŸ“¦ Assign Multiple Values

# Multiple variables, multiple values
a, b, c = 1, 2, 3

# One value to multiple variables
x = y = z = "Hello"
  
🧠 Tip: Use descriptive variable names like user_age instead of x, especially in real projects.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review