LEARN MATE Request book Contact us quizes Books Home
Variables
Variable is a name that is used to refer to memory location. Python variable is also known as an identifier and used to hold value. In Python, we don't need to specify the type of variable because Python is a infer language and smart enough to get variable type. Variable names can be a group of both the letters and digits, but they have to begin with a letter or an underscore. name = "Devansh" age = 20 marks = 80.50 print(name) print(age) print(marks)

This syntax can be used to declare both local and global variables.

In the above example, we have declared a few valid variable names such as name, _name_ , etc. But it is not recommended because when we try to read code, it may create confusion. The variable name should be descriptive to make code more readable. x=y=z=50 print(x) print(y) print(z) Note: If you assign a new value to an existing variable, it will overwrite the previous value:

If you don't want others (or yourself) to overwrite existing values, use the final keyword (this will declare the variable as "final" or "constant", which means unchangeable and read-only):

x = "mohan" y = True z = 4.9 print(x) print(y) print(z)