Python Keywords and Identifiers
In this tutorial, you will learn about Identifiers (names given to variables, functions, etc.) and keywords (basically these are reserved words in Python).
Python Keywords
- Keywords are the reserved words in Python.
- We cannot use a keyword as a function name or a variable name or any other identifier. They are used to define the structure and syntax in the Python language.
- In Python, keywords are case sensitive.
There are 33 keywords in Python 3.7:
- All the keywords except some those are True, False and None are in lowercase.
- They must be written in the same way they are.
The Complete list of all the keywords is given below:
- True
- False
- None
- and
- as
- assert
- async
- await
- break
- class
- continue
- def
- del
- elif
- else
- except
- finally
- for
- from
- global
- if
- import
- in
- is
- lambda
- nonlocal
- not
- or
- pass
- raise
- return
- try
- while
- with
- yield
If you want to have an overview of Keywords, here is the complete list of all the keywords with examples.
Python Identifiers
The identifier is a name given to entities like variables, class, functions, etc. It helps to differentiate between one entity from another.
Rules for writing identifiers:
- Identifiers can be the combination of letters in Uppercase (A to Z) ,in lowercase (a to z), digits (0 to 9) or can be an underscore _.
- Names like myClass, roll_no_1 and print_this_to_screen, all are valid example.
- An identifier cannot start with a digit.
- 1variable is invalid, but
- variable1 is a valid name.
- Keywords cannot be used as identifiers.
- We cannot use special symbols like !, @, #, $, % etc. in our identifier.
- The identifier can be of any length.
Most Important Things to Remember:
- Python is a case-sensitive language.
- This means identifier and Identifier are not the same.
- Always give the identifiers a name that makes some sense which should be easily understood. While df = 10 is a valid name but writing roll_no= 10 would make more sense, and it would be easier to figure out what our code represents.
- Multiple Numbers of words can be separated using an underscore, like this_is_a_called_identifiers.
Comments
Post a Comment
Please do not enter any spam links in the comment box.