In Python, keywords are specific words that have a special meaning in the language. For example, the keyword def
is used to define a function, and the keyword for
is used to create a for loop to iterate over a sequence of values.
There are approximately 33 keywords in Python, and they cannot be used as variable names because they are reserved for specific purposes in the language.
Here is a list of some common Python keywords:
and
as
assert
break
class
continue
def
del
elif
else
except
False
finally
for
from
global
if
import
in
is
lambda
None
nonlocal
not
or
pass
raise
return
True
try
while
with
yield
Quiz
-
What is the keyword used to define a function in Python?
-
A. def
-
B. function
-
C. lambda
-
D. try
-
-
What is the keyword used to create a for loop in Python?
-
A. for
-
B. loop
-
C. iterate
-
D. while
-
-
What is the keyword used to specify an exception handler in a try-except block in Python?
-
A. else
-
B. finally
-
C. except
-
D. raise
-
-
What is the keyword used to indicate the end of a loop in Python?
-
A. break
-
B. continue
-
C. return
-
D. pass
-
-
What is the keyword used to import a module or package in Python?
-
A. import
-
B. from
-
C. global
-
D. nonlocal
-