- Python Basics
- Python Home
- Python History
- Python Applications
- Python Features
- Python Versions
- Python Environment Setup
- Python Basic Syntax
- Python end (end=)
- Python sep (sep=)
- Python Comments
- Python Identifiers
- Python Variables
- Python Operators
- Python Ternary Operator
- Python Operator Precedence
- Python Control & Decision
- Python Decision Making
- Python if elif else
- Python Loops
- Python for Loop
- Python while Loop
- Python break Statement
- Python continue Statement
- Python pass Statement
- Python break Vs continue
- Python pass Vs continue
- Python Built-in Types
- Python Data Types
- Python Lists
- Python Tuples
- Python Sets
- Python frozenset
- Python Dictionary
- List Vs Tuple Vs Dict Vs Set
- Python Numbers
- Python Strings
- Python bytes
- Python bytearray
- Python memoryview
- Python Misc Topics
- Python Functions
- Python Variable Scope
- Python Enumeration
- Python import Statement
- Python Modules
- Python operator Module
- Python os Module
- Python Date & Time
- Python Exception Handling
- Python File Handling
- Python Advanced
- Python Classes & Objects
- Python @classmethod Decorator
- Python @staticmethod Decorator
- Python Class Vs Static Method
- Python @property Decorator
- Python Regular Expressions
- Python Send E-mail
- Python Event Handling
- Python Keywords
- Python All Keywords
- Python and
- Python or
- Python not
- Python True
- Python False
- Python None
- Python in
- Python is
- Python as
- Python with
- Python yield
- Python return
- Python del
- Python from
- Python lambda
- Python assert
- Python Built-in Functions
- Python All Built-in Functions
- Python print() Function
- Python input() Function
- Python int() Function
- Python len() Function
- Python range() Function
- Python str() Function
- Python ord() Function
- Python chr() Function
- Python read()
- Python write()
- Python open()
- Python Examples
- Python Examples
- Python Test
- Python Online Test
- Give Online Test
- All Test List
Python Identifiers
As name suggests, identifier is a name that identifies an object in a Python program. Object may be a variable, class, function etc. For example:
var = "codescracker.com" a = 100 b = 200 def myfun(): print(var) class myclass: def sum(self, num_one, num_two): return num_one+num_two myfun() obj = myclass() print("Sum = ", obj.sum(a, b))
In above program, the list of identifiers are:
- var
- a
- b
- myfun
- myclass
- sum
- num_one
- num_two
- obj
where myfun and sum are the two identifiers used to name functions, myclass is another identifier used to name class, and all others are used to name variables. Basically, identifiers are building-block of a Python program. The output produced by above program should exactly looks like:
Don't worry about the code, just look at the identifiers only. You'll learn all the things like functions, classes etc. in upcoming chapters one by one.
Important - Identifiers should not be a keyword.
Note - Python is a case-sensitive programming language. Case-sensitive means, num, Num, NUM, nUm, nuM are all different variables or identifiers.
How to Name an Identifier in Python ?
To name an identifier in Python, we can use the combination of letters (a-z, A-Z), numbers (0-9) and underscore (_). For example, codescracker, codes_cracker, codes12cracker_, codes123 etc.
Rules to Name Identifiers in Python
Here are the list of rules that must be followed while naming or creating a variable, class, function etc. in Python:
- Identifiers must start with a letter or an underscore
- Or Identifiers can not start with any character other than A-Z, a-z, or _ (underscore)
- After A-Z, a-z, or _, you can use any combination of A-Z, a-z, 0-9, and _
- Identifiers in Python can not be named using Python's keyword
- So, I recommend you to see the list of Python keyword before naming identifier
Python Identifiers Example
Let's create a program in Python proves that Python is a case-sensitive language. That is, two identifiers say num and Num gets treated as two different identifiers by the compiler:
num = 11 Num = 12 NUM = 13 nUm = 14 nuM = 15 print(num) print(Num) print(NUM) print(nUm) print(nuM)
The snapshot given below shows the exact output produced by above Python program:
You see! all the identifier prints different value, but the name is same if their case gets ignored. If Python is not a case-sensitive language, then the output should be 15, five times. That is, if you replace the above program with the program given below:
num = 11 num = 12 num = 13 num = 14 num = 15 print(num) print(num) print(num) print(num) print(num)
Then the output must be equal to the snapshot given below:
« Previous Tutorial Next Tutorial »
Follow/Like Us on Facebook
Subscribe Us on YouTube