Identifiers
In Python, keywords are predefined and reserved words with specific meanings. The syntax of the code is defined by keywords. The keyword can't be used as a variable name, function name, or identifier. Except for True and False, all keywords in Python are written in lower case. Let's have a look at each of the 33 keywords in Python 3.7 one by one.
Identifiers: An identifiers in python is a name that is used to identify a variable, function, class, module, or other type of object. The identifier is made up of a series of digits and underscores. The identification should begin with a letter or an Underscore and then be followed by a digit. A-Z or a-z, an UnderScore (_), and a digit are the characters (0-9). Special characters (#, @, $, percent,!) should not be used in identifiers.
Rules for writing identifiers
- Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore
_
. Names likemyClass
,var_1
andprint_this_to_screen
, all are valid example. - An identifier cannot start with a digit.
1variable
is invalid, butvariable1
is a valid name. - Keywords cannot be used as identifiers.
Outputglobal = 1
File "<interactive input>", line 1 global = 1 ^ SyntaxError: invalid syntax
- We cannot use special symbols like !, @, #, $, % etc. in our identifier.
a@ = 0
OutputFile "<interactive input>", line 1 a@ = 0 ^ SyntaxError: invalid syntax
- An identifier can be of any length.
Comments
Post a Comment