What is a Variable?
A variable is a named container that is used to store data in a Python program. It provides a way to save information in memory so that the program can use, update, or access that information whenever it is needed. Instead of writing the same value multiple times, we store it in a variable and refer to it by its name. This makes the program easier to read, write, and maintain.
A variable can store different types of data such as text, numbers, decimal values, or Boolean values. In Python, there is no need to declare the data type before creating a variable. Python automatically identifies the data type based on the value assigned to it. This feature is known as Dynamic Typing.
name = "Vikram"
age = 25
price = 99.99
is_student = True
In the above example, name, age, price, and is_student are variables. The values assigned to these variables are stored in memory and can be accessed anywhere in the program by using the variable name.
A variable does not permanently store a single value. Its value can be changed whenever required by assigning a new value. When a new value is assigned, Python replaces the old value with the new one.
age = 25
age = 26
After executing the above statements, the value stored in age becomes 26. The previous value (25) is replaced.
A meaningful variable name makes the program easy to understand. Variable names should clearly describe the data they store. For example, student_name, total_marks, and employee_salary are better choices than short or unclear names.
Python follows a few naming rules while creating variables. A variable name must begin with a letter or an underscore (_). It can contain letters, numbers, and underscores, but it cannot start with a number or contain special characters such as @, #, or -. Variable names are also case-sensitive, which means name, Name, and NAME are treated as three different variables.
student_name = "John" # Valid
_total = 500 # Valid
1name = "John" # Invalid
my-name = "John" # Invalid
One of the most important features of Python variables is Dynamic Typing. The same variable can store different types of values during program execution because Python automatically detects the data type.
x = 10
x = "Hello"
x = 12.5
In this example, the variable x first stores an integer, then a string, and finally a floating-point number. Python accepts all these assignments without requiring explicit type declarations.
Variables are widely used in real-world applications. For example, in a login automation script, a username and password are stored in variables so that the same values can be reused whenever required.
username = "vikram123"
password = "Welcome@123"
Using variables improves code readability, reduces repetition, makes programs easier to modify, and helps developers write reusable and maintainable code.
Key Points
A variable is a named container used to store data.
Variables allow data to be stored, accessed, and updated.
Python automatically identifies the data type (Dynamic Typing).
Variable values can be changed during program execution.
Meaningful variable names improve code readability.
Variable names must follow Python naming rules.
Variables make programs reusable, maintainable, and easier to understand.
Sur cette page du site, vous pouvez voir la vidéo en ligne what is variable in python durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Images learning 07 juillet 2026, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 5 fois et il a aimé 0 téléspectateurs. Bon visionnage!