Variables and Assignments in Python
💡 What is a Variable?
A variable is like a container or a box in the computer's memory that stores a value.
Think of it like naming a jar to store something inside. The jar (variable) holds the value, and you can use that name anytime to get or change what's inside.
Example:
x = 10
Here:
xis the variable name10is the value=is the assignment operator
You can now use x in your program, and Python knows it means 10.
✅ Why Use Variables?
Variables:
- Help you store data
- Make your code easy to read and update
- Let you perform calculations
- Are used in almost every program!
📥 Assignment in Python
In Python, we use the equal sign = to assign a value to a variable.
name = "Ansh"
age = 7
score = 92.5
namestores a word (string)agestores a number (integer)scorestores a decimal (float)
✅ Summary
- A variable stores a value using a name
- The
=sign is used to assign values - You can change or update variables any time
- Variable names must follow certain rules
- Python supports different data types like
int,float,str, andbool - Use
type()to check what kind of value a variable holds
No comments:
Post a Comment