Python Variables -
Beginner Notes
- A variable stores a value.
- Think of it like a box with a
name.
What is a
Variable?
- You can change or reuse
the value anytime.
- Used to store and manage
data in a program.
- Store data temporarily while
Store the program runs.
Why Are
- Reuse values without
Variables Reuse repeating.
Important?
- Make code easier to read and
Make maintain.
Syntax to Create a Variable
• Syntax:
• variable_name = value
• Example:
• name = "Anil"
• age = 21
Rules for Variable Names
- Start with a letter or underscore (_)
- Cannot start with a number
- No spaces allowed
- Can use letters, numbers, and underscores
- Case-sensitive (Name ≠ name)
Valid Variable Examples
• name = "Anil" # string
• age = 21 # integer
• marks = 85.5 # float
• is_passed = True # boolean
Invalid Variable Examples
• 1name = "Anil" # starts with number
• student name = "A" # contains space
• @roll = 23 # invalid character
Using print() with Variables
• name = "Anil"
• age = 21
• print("Student Name:", name)
• print("Age:", age)
• Output:
• Student Name: Anil
• Age: 21
Updating Variables
• age = 21
• age = 22 # updated value
• print(age) # Output: 22