Variables are used to store values in the memory of a computer. a variable name is a name that given to the memory block of the computer to store the value which we assign to the variable. Why use variables in python?
Why use variables?
- When you are writing a long program and need to use a value often and which is long, then you can use a short variable name instead of a long value.
- When you take input from the user you need to save it somewhere for later use in the program.
To declare Variables In Python, you have to first give a name to it and also you have to declare some values. Later, whenever we use that variable name in our code it will use that variable value in the place of the variable name while executing. so, basically, they store the values to access later.
Defining a Variables In Python
- Syntax to define a variable
Variable name = variable value
- You can change the value of a variable any time. When you assign a new value to the variable it will modify the value in the computer memory and it will use this new value in the future. Have a look at this example.
- You can assign values to multiple variables at once
Rules to define a variable name
- Can only contain alpha-numeric characters and underscore (A-z, 0-9, _ )
- Starts with any letter or an underscore character(_)
- Doesn’t start with a number
- A variable name is case-sensitive in python.
- Can’t use reserved key-words
In python, unlike some other languages, you don’t have to declare the variable type. It will automatically do it on the basis of the value you assign to it.
To know which keywords are reserved python, just execute this following command
Blog you may like : Comment In Python
If you have any questions you can Message me on Instagram