Python Identifiers: Identifier is the name used to identify a variables, class, modules, function and other object of python. As you identify by your name. For example this website is identify by name "EEEHUB".
There are some conversion or rules you need to follow while naming the objects of the python programming language. These conversion will also help you to understand the code of other python developers. So, let see them one by one.
- First letter of the name should be letter from (a to z) or (A to Z) or underscore (_) followed by letters, digits(0-9). Remember: No special character(s) are allowed except underscore.
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 9A = "Hello World"
SyntaxError: invalid syntax
>>> _A = "Hello World"
- Python is case sensitive programming language. It means for python language EEEHUB and eeehub will be different identifiers.
>>> EEEHUB = "First Identifier"
>>> eeehub = "Second Identifier"
- Class names start with an uppercase letter. All other identifiers start with a lowercase letter for example: Users (It is perfect class name.)
>>> class User:
- Starting an identifier with a single leading underscore indicates that the identifier is private for example: _userage (You have to understand that this is private identifier.)
- Starting an identifier with two leading underscores indicates a strong private identifier for example: __userpassword(strong private identifier)
- If the identifier also ends with two trailing underscores, the identifier is a language defined special name for example: __add__
- Reserves word can't be used for identifier for example print(). print is a reserve word in python language.