Wednesday, 25 June 2025

Variables and Assignments in Python

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:

  • x is the variable name
  • 10 is 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
  • name stores a word (string)
  • age stores a number (integer)
  • score stores 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, and bool
  • Use type() to check what kind of value a variable holds

No comments:

Post a Comment

Total Pageviews

Search This Blog

Write a program which performs the following operations using a simple queue. : insert() -> delete() -> display()

Write a program which performs the following operations using a simple queue. : insert() -> delete() -> display() ...