A variable is a named container that stores a value. Think of it as a labeled box where you can put data. In Python, you don't need to declare the type of variable - Python figures it out automatically.
To create a variable, use the assignment operator =:
name = "Alice"
age = 25
height = 5.6
is_student = True
Whole numbers without decimal points:
age = 25
score = 100
temperature = -5
Numbers with decimal points:
price = 19.99
temperature = 36.6
pi = 3.14159
Text data enclosed in quotes:
name = "Python"
message = 'Hello World'
greeting = """Multi-line
string example"""
True or False values:
is_active = True
has_permission = False
is_valid = True
user_name = "John"
student_age = 20
total_score = 95
is_logged_in = True
x = "John" # Not descriptive
1name = "John" # Starts with number
user-name = "John" # Contains hyphen
if = 5 # Python keyword
Use the type() function to check the data type:
name = "Alice"
age = 25
height = 5.6
print(type(name)) #
print(type(age)) #
print(type(height)) #
type() to check variable typesCreate variables for your personal information (name, age, height, is_student) and print them using the code editor!
Open Code Editor