Identifiers or variables are used to store the constant values in a program.
⇨Variables:- A variable in python represent named location that refers to a value and whose values can be used and processed during program run.
Some examples:-
marks=70
student='jacob'
Age=16
Here the variables are marks , student , Age .which stores various values .
Note - A variable stores only one value at a time .
ex.. age=15
age=20
So, the final value stored in variable 'age' is 20 not 15
Note--A variable is not created until some value is assigned to it...
example---
Examples:::
⇨lvalue and rvalue:--
•lvalue: expressions that come on the lhs(left hand side) of an assignment.
•rvalues: expressions that come on the rhs(right hand side) of an assignment.
e.g., you can say that
a=20
b=10
But you cannot say
20=a
10=b
⇨Multiple Assignments:
1. Assigning some value to multiple variables
ex---
a=b=c=10
2.Assigning multiple values to multiple variables
ex---
x,y,z=10,20,30
There are some rules for identifiers :-
→An identifier is an arbitrarily long sequence of letters and digits.
→The first character must be letter , underscore( _ ) counts as letter.
→Upper and lower-case letters are different.
→Identifiers are unlimited in length.
→An identifier cannot contain any special character except for underscore ( _ ).
→An identifier must not be keyword of python
{Keyword:-It is a small word having special meaning reserved by programming language}
Examples of identifiers :-
Myfile , date9_7_77 , Z2T0Z9 , _CHK , FILE13 etc. these are valid identifiers
Invalid :- DATA-REC , 29CLCT , My.file , break . etc
let's understand this deeply with examples in interpreter :-
here we can see that :-
↪'a' and '_CHK' is valid identifiers which store 2 and 'python' respectively.
↪But 'break' is a keyword as well as invalid identifier . so python produces error.
↪'My.file' is also invalid identifier.