The user-defined names that are given to Functions or variables are known as Identifiers. It helps in differentiating one entity from another and also serves as a definition of the use of that entity sometimes. As in every programming language, there are some restrictions/ limitations for Identifiers. So, is the case with Python, we need to take care of the following points before using an Identifier.
Rules for writing Identifiers:
- The first and foremost restriction is that Identifiers cannot be the same as Keywords. There are special reserved keywords in every programming language that has its own meaning and these names can’t be used as Identifiers in Python.
File "/home/9efd6943df820475cf5bc74fc4fcc3aa.py", line 15 def = 12 ^ SyntaxError: invalid syntax
- An identifier in Python cannot use any special symbols like !, @, #, $, % etc.
File "/home/3ae3b1299ee9c1c04566e45e98b13791.py", line 13 var@ = 12 ^ SyntaxError: invalid syntax
- Apart from these restrictions, Python allows Identifiers to be a combination of lowercase letters (a to z) or uppercase letters (A to Z) or digits (0 to 9) or an underscore (_). But variable name must not be started with digits. Names like myClass, var_3, and print_to_screen, are valid examples.
2020 This is a string QWERTY
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course