Key words in Python

Generally, every programming language has syntax like the same python has its own syntax, key words, literals and identifiers.

In the previous posting we learn how to execute single commands and multiple commands in shell. Now we focused on keywords in python.

As we know a keyword is a reserve word which has a meaning and specific functionality in the programming language. These keywords should not used as a constants or variable in the programming.

Below is the list of python keywords.

SnoKeywordUsage
1andA logical operator
2asTo create an alias
3assertFor debugging
4breakTo break out of a loop
5classTo define a class
6continueTo continue to the next iteration of a loop
7defTo define a function
8delTo delete an object
9elifUsed in conditional statements, same as else if
10elseUsed in conditional statements
11exceptUsed with exceptions, what to do when an exception occurs
12FALSEBoolean value, result of comparison operations
13finallyUsed with exceptions, a block of code that will be executed no matter if there is an exception or not
14forTo create a for loop
15fromTo import specific parts of a module
16globalTo declare a global variable
17ifTo make a conditional statement
18importTo import a module
19inTo check if a value is present in a list, tuple, etc.
20isTo test if two variables are equal
21lambdaTo create an anonymous function
22NoneRepresents a null value
23nonlocalTo declare a non-local variable
24notA logical operator
25orA logical operator
26passA null statement, a statement that will do nothing
27raiseTo raise an exception
28returnTo exit a function and return a value
29TRUEBoolean value, result of comparison operations
30tryTo make a try…except statement
31whileTo create a while loop
32withUsed to simplify exception handling
33yieldTo end a function, returns a generator

Remember All the Python keywords contain lowercase letters only.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top