What Are Variables In Python - Python Notes By Mr. BILRED - TechAmbitionX
What Are Variables in Python?
Alright, let’s keep it simple.
A variable is just a name that stores some value. Like a box with a label on it.
When you write:
x = 5
You’re saying: “Hey Python, make a box called x
, and put the number 5
inside it.”
Some Examples:
name = "Bilal"
age = 21
pi = 3.14
You can use these variables later in your program:
print(name)
print(age + 1)
Variables Can Store:
- Numbers (
int
,float
) - Text (called
strings
) Boolean
values (True
orFalse
)- Lists, dictionaries, and more
Variable Naming Rules:
In x = 10
"x" is the identifier for the variable storing the value 10. Try not to forget the following rules
- Don’t start names with a number
- No spaces allowed (use underscores like
user_name
) - Use meaningful names (atleast when you're showing that to your boss)
Wanna Try?
x = "Mr. BILRED"
print("Welcome,", x)
You’ll see:
Welcome, Mr. BILRED
Yup. That’s your first dynamic print(if you did it first time, obviously).
bGlmZSBtb3ZlcyBwcmV0dHkgZmFzdCwgbWFuLi4uIEdvIGxpdmUgYSBsaXR0bGUh
Understand The Topics:
Comments
Post a Comment