Identifier in python: In this Page, We are Providing Basics of Python – Variable, Identifier and Literal. Students can visit for more Detail and Explanation of Python Handwritten Notes Pdf.
Basics of Python – Variable, Identifier and Literal
Variable, identifier, and literal
A variable is a storage location that has an associated symbolic name (called “identifier”), which contains some value (can be literal or other data) that can change. An identifier is a name used to identify a variable, function, class, module, or another object. Literal is a notation for constant values of some built-in type. Literal can be string, plain integer, long integer, floating-point number, imaginary number. For e.g., in the expressions
var1=5 var2= 'Tom'
var1 and var2 are identifiers, while 5 and ‘ Tom’ are integer and string literals, respectively.
Consider a scenario where a variable is referenced by the identifier a and the variable contains a list. If the same variable is referenced by the identifier b as well, and if an element in the list is changed, the change will be reflected in both identifiers of the same variable.
>>> a = [1, 2, 3] >>> b =a >>> b [1, 2, 3] >> a [ 1 ] =10 >>> a [1, 10, 3] >>> b [1, 10, 3]
- Python Programming – Basics of Python
- Literals in Python
- Python Interview Questions on Data Types and Their in-built Functions
Now, the above scenario can be modified a bit, where a and b are two different variables.
>>> a= [1,2,3 ] >>> b=a[:] # Copying data from a to b. >>> b [1, 2, 3] >>> a [1] =10 >>> a (1, 10, 3] >>> b [1, 2, 3]
There are some rules that need to be followed for valid identifier naming:
- The first character of the identifier must be a letter of the alphabet (uppercase or lowercase) or an underscore (‘_’).
- The rest of the identifier name can consist of letters (uppercase or lowercase character), underscores (‘_’), or digits (0-9).
- Identifier names are case-sensitive. For example, myname and myName are not the same.
- Identifiers can be of unlimited length.