Mohit Raj
Posted on November 3, 2019
variables :
- Variables are nothing but reserved memory locations to store values. It means that when you create a variable, you reserve some space in the memory.
- Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory.
There are different types of data types in python:
a. Numbers
b. String
c. List
d. Tuple
e. Dictionary
Note: I will discuss these all in separate sectionA variable can hold different types of values.
for example if you assign a string to a variable then that variable belong to string data types,and if you assign number to the same variable the its belong to number data types.
Means to say that you can store any type of variable in any variable,that variable behaves according to that particular data type. need not to declare data type before the variable name (as done in language like C and C++).
How to declare variable
- For declaration of variable in python no need to declare data type of it.
Syntax : variable_name = assigned_value
example :
name="abc"
x=23
roll=1 etcYou may assign values to more than one variable at a time.
example : a=b=c=2 means a=2,b=2,c=2.You may also assign like this_
a,b=2,3 i.e. a=2 and b=3 (this is not possible in language like C or C++)
Rules for declaration of a variable
- Variable name not start with a number (show syntax error) but you can use number inside the variable name.
Variable name only starts with any letters ,underscore(_) . this is for the first letter of the variable name
Not use any special symbol ($,^,@,%) in the variable name neither at the start nor in the middle or end.
keywords are not variables. They just have special meaning to the interpreter..
See below list for the python keywords these are not used as a variable :
=>> This is all about variable as we continue we know more about variables as we go deeper in it.
Thank You....
Posted on November 3, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.