Python Variables

A variable is a name which is used to reserve space in memory for storing values.

A variable in Python is created when we assign a value to it.

Example

name = "Danny"
contact_number = 987654
amount = 150.60
status = True
print(name)
print(contact_number)
print(amount)
print(status)
  
Output
Danny
987654
150.6
True

Python is dynamically typed programming language, meaning we do not need to declare data type of a variable. The type of a variable can also be changed by reassigning a new value of another type to already declared variable.

Example

name = "Danny"
name = 987654
print(name)
  
Output
987654

How to name a variable?

Use small letters and in case of multiple words, separate words by underscore to improve readability.

Example

user_name = "Danny"
color = "Red"
_customer_email = "danny@tutorialsbuddy.com"
x = 100