Python is a high-level programming language used widely by developers across the globe. It is a case sensitive language which means “World” and “world” are not the same because the case “W” and “w” differs in both the words. Let’s dive in to know more about Python identifiers and their case sensitivity.
Also read: What is the difference between Python 2 and Python 3?
What are identifiers?
Keywords are the reserved words in python which has special meaning associated with them. Example: while, True, False, print etc.
Identifiers are the names given to a variable or class or methods by the developer to distinguish between different entities. Example: variable_10, address, email_ID, _age, etc.
The developer can give any name to the identifier that he/she wants to give. However there are some rules that should be followed while writing identifiers. Let’s go through those rules below.
Rules for writing identifiers
- Identifiers can have letters in lowercase or uppercase (a-z, A-Z), numbers (0-9) and an underscore (_).
- No special symbols (@, #, $, %, !) should be present in the identifier.
- The identifier should not start with a digit. It can start with an underscore or any letter be it lowercase or uppercase.
- You cannot use keywords as Identifiers.
As you can see in the example above, if you try to use special symbols in the identifier or start an identifier with a digit or use keyword as an identifier the python will throw you error as these are not allowed. You can only have letters (lowercase/uppercase) or digits or an underscore in an identifier.
Also read: 5 algorithms every developer should know
Python is case sensitive when dealing with identifiers
Python is a case sensitive language which means the identifiers are also case sensitive. The identifier “abc” is not the same as “ABC” because even if the letters are same the case of these identifiers are different. Thus, these are treated as two different identifiers.
Here, you can see in the above example the variable name and Name are different and contains different values.
Thus, python treats identifiers as case-sensitive words.
Also read: How to create a list in Python?