Vivaan KOHLI
last year
Vivaancountry asked

What is a variable?

Kelish Rai
Expert
last year
Kelish Rai answered

Simply put, variables are containers for data.

For example, let's say your favorite book is Harry Potter and the Sorcerer’s Stone, and you want to use its name multiple times in a program. Instead of typing it every time like this:

print("Harry Potter and the Sorcerer’s Stone")
print("Harry Potter and the Sorcerer’s Stone")
print("Harry Potter and the Sorcerer’s Stone")

You can store it in a variable and use it whenever needed:

book = "Harry Potter and the Sorcerer’s Stone"

print(book)
print(book)
print(book)

This makes the code cleaner, easier to work with, and more efficient. If you ever need to change the book name, you only need to update the variable instead of modifying multiple lines of code.

It's okay if you don't fully understand how this works yet. As you continue with the course, you'll get a clearer understanding of variables and how they help in programming.

Let me know if anything is unclear—I’m happy to help.

Python
This question was asked as part of the Getting started with Python course.