Python Data Presistence – Identifiers

Python Data Presistence – Identifiers

Python identifiers are the various programming elements such as keywords, variables, functions/methods, modules, packages, and classes by suitable name. Keywords are reserved words with predefined meanings in Python interpreter. Obviously, keywords can’t be used as the name of other elements as functions etc. Python language currently has 33 keywords. Enter the following statement in Python’s interactive console. The list of keywords gets displayed!

Example

>>> import keyword
>>> print (keyword.kwlist)
[‘False ‘, ‘None’, ‘True’, ‘ and’, ‘as’, ‘assert’, ‘break’ , ‘class’, ‘continue ‘, ‘def’, ‘del’, ‘elif’, ‘ else’ , ‘except’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘ if’, 1 import’, ‘in’, ‘is’ , ‘lambda’, ‘nonlocal’, ‘ not’ , ‘while’ ‘or’, ‘pass’, ‘raise ‘return’, ‘try’, ‘with’, ‘yield’]

Apart from keywords, you can choose any name (preferably cryptic but indicative of its purpose) to identify other elements in your program. However, only alphabets (upper or lowercase), digits, and underscore symbols (‘_’) may be used. As a convention, the name of the class starts with an uppercase alphabet, whereas the name of the function/method starts with the lowercase alphabet. The name of a variable normally starts with an alphabet, but in special cases, an underscore symbol (sometimes double underscore ) is seen to be the first character of the variable’s name.

Some examples of valid and invalid identifiers:

Valid identifiers

Invalid identifiers

name, FileName, yrlseml, EMP, roll_no, sum_of_dig,

_price, _salary, _ function_

123, sub-1, yr1.sem1, roll no, ‘price’, *marks*