{"id":2803,"date":"2021-04-17T10:21:33","date_gmt":"2021-04-17T04:51:33","guid":{"rendered":"https:\/\/python-programs.com\/?p=2803"},"modified":"2021-11-22T18:45:14","modified_gmt":"2021-11-22T13:15:14","slug":"basics-of-python-variable-identifier-and-literal","status":"publish","type":"post","link":"https:\/\/python-programs.com\/basics-of-python-variable-identifier-and-literal\/","title":{"rendered":"Basics of Python \u2013 Variable, Identifier and Literal"},"content":{"rendered":"

In this Page, We are Providing Basics of Python \u2013 Variable, Identifier and Literal. Students can visit for more Detail and Explanation of Python Handwritten Notes<\/a> Pdf.<\/p>\n

Basics of Python \u2013 Variable, Identifier and Literal<\/h2>\n

Variable, identifier, and literal<\/strong><\/p>\n

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<\/p>\n

var1=5 \r\nvar2= 'Tom'<\/pre>\n

var1 and var2 are identifiers, while 5 and ‘ Tom’ are integer and string literals, respectively.<\/p>\n

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.<\/p>\n

>>> a = [1, 2, 3]\r\n>>> b =a \r\n>>> b \r\n[1, 2, 3]\r\n>> a [ 1 ] =10\r\n>>> a\r\n[1, 10, 3]\r\n>>> b\r\n[1, 10, 3]<\/pre>\n

Now, the above scenario can be modified a bit, where a and b are two different variables.<\/p>\n

>>> a= [1,2,3 ]\r\n>>> b=a[:] # Copying data from a to b.\r\n>>> b \r\n[1, 2, 3]\r\n>>> a [1] =10 \r\n>>> a \r\n(1, 10, 3]\r\n>>> b\r\n[1, 2, 3]<\/pre>\n

There are some rules that need to be followed for valid identifier naming:<\/p>\n