variables,the name itself implies that a variable is something which can change.
Variables are like containers for storing our data values in memory.
we can change the data in variables, in python everything is an object and variables are like names given to the object, by labeling them we can easily access them.
In other high level languages like C programming language, c++ programming language, and java programming language. etc., we need to declare the datatype of the variable , but in python it will automatically recognize the type of data you are storing in a variable.
** Remember that a variable is a name which is given to a value not to the memory.
Declaring a variable is very easy you need to assign a value or a string using '=' operator.
>>> p=9
>>> print(p)
9
Assigning a single value to multiple variables
>>> a=b=c=56
>>> a
56
>>> b
56
>>> c
56
Assigning different values to multiple variables
>>> a,b,c=28,'python',56.3
>>> a
28
>>> b
'python'
>>> c
56.3
*** If we use the same variable for different values, that variable will start checking for a new value or a recent value given by the user.
>>> a=49
>>> a='python'
>>> print(a)
python
Rules for Creating variables in Python Programming
- A variable name should start with a letter or the underscore character.
- It should contain only Alphanumeric characters and underscores (A-z,0-9, _).
- It cannot start with any number or digits.
- Variable names are case sensitive which means python, PYTHON, Python are different variables.
Examples of naming Variables in Python
newvar = “python”
new_var = “python”
_ new_var = “python”
Newvar = “python”
NewVar = “python”
NEWVAR = “python”
Newvar 3 = “python”
EXAMPLE
x=3 # x is integer type
y='python' # y is of string type
print(x)
print(y)
OUTPUT
3
python
Previous
Python Program to check if the given number is even or odd
Next
Comments
Post a Comment