Python Keywords and Identifiers
This tutorial will teach about keywords and identifiers, which will include reserved words in python.
Python Keywords
Python keywords are the python reserved words reserved by python language secured to define the python syntax and structure of the python language. We cannot use these reserved keywords as variable names, function names, class names, or other identifiers. In python, all the keywords are case-sensitive. All the python keywords should contain lowercase letters only except True, False, and None must be written as they are.
The following list shows the keywords in python.
Keyword | Description |
---|---|
True | This keyword represents the Boolean Value ‘true.’ |
False | This keyword represents the Boolean Value ‘false.’ |
None | This keyword represents the Null Value |
and | This is a logical operator |
as | This keyword used for creating an alias |
assert | The assert keyword is used to insert debugging assertions in the program. |
async | This keyword is always used in the coroutine function body. |
await | This keyword is used for asynchronous processing. |
break | This keyword is used to break the loop. |
class | This keyword is used to define a class. |
continue | This keyword is used to take the control back to the loop. |
def | This keyword is used to define a function. |
del | This keyword is used to delete objects like variables, lists, or any other kind of object. |
Elif | This keyword is used for a conditional statement along with an if statement. |
else | This keyword is also used as a conditional statement, the same as above. |
except | This keyword is used for exceptional handling in Python. |
finally | This keyword is used for exceptional handling, but finally, the block will always get executed. |
for | This keyword is used as a looping statement used to iterate over the elements of a sequence. |
from | This keyword is used to import a function in python. |
global | This keyword is used to declare global variables. |
if | This keyword is used to declare a condition in Python. |
import | This keyword is used for importing the module in python. |
in | This keyword is used to check specific values are present in an iterable object. |
is | This keyword is used to test object identity |
lambda | This keyword is used to make anonymous functions. |
nonlocal | This keyword is used to access the variables defined outside of the scope in the block. |
not | This keyword is used to negates a Boolean value. |
or | This keyword is used for a conditional statement where at least one condition must be fulfilled. |
pass | This keyword is used to tell the program or a function to do nothing. |
raise | This keyword is used to create a user define exception. |
return | This keyword is used to return a value at the time function is exited |
try | This keyword is used to specifies the exception handlers. |
while | This keyword is used to run a block of statements till the expression is fulfilled |
with | This keyword is used to open a file. |
yield | This keyword is a replacement for a return keyword. |
At first, this keyword will look very difficult to understand but believe me, all the keywords will make sense once we continue with our python tutorial, and if your want to learn in-depth about keywords with examples, you can see this (Link to another page for keywords in details)
To see the latest list of python keywords, we can follow the following steps.
Step 1: Open Python IDLE or Python Interpreter
Step 2: type the help() command to access the help shell.
Step 3: type keywords on the help shell, and you will get the following result.
Python Identifiers
What are identifiers in python?
The identifiers in python are a name used to identify a variable, function, class, module, or other objects. An identifier follows specific python rules that can combine an uppercase letter from A - Z or a lowercase a - z. It can also start with an underscore(_) followed by any number from 0 - 9 or letter.
Example a_data, a1, This_is_variable, and v_3 all are valid identifiers.
An identifier like 1name is invalid, and it cannot start with a digit. Also, keywords cannot be used as identifiers.
Python identifiers examples
Lets us see some examples of valid and invalid identifiers in python
Below are the list of valid python identifiers.
- abc123
- abc_de
- _abc
- ABC
- abc
Below is the examples of invalid identifiers in python.
- 123abc
- abc@
- 123
- for
FAQ
Question: Are python variable case sensitive?
Answers: Yes, the Python variable is case sensitive; both “Python” and “python” are different in a python programming language.
Question:Is python case sensitive when dealing with identifiers?
Answers:Yes, Python is case-sensitive when we are dealing with identifiers.