Reserved Words
Reserved word in
any programming language is a word which has some fixed meaning and cannot be
redefined by the programmer.
Reserved means “kept
for some special purpose”
In Python, some
words are reserved to represent some meaning or functionality.
Such words are called as Reserved words.
There are 33 reserved words available in Python.
- True, False, None
- and, or ,not, is
- if, elif, else
- while, for, break, continue, return, in, yield
- try, except, finally, raise, assert
- import, from, as, class, def, pass, global, nonlocal, lambda, del, with
Note:
1. All Reserved words in Python contain only
alphabet symbols.
2. Except the following 3 reserved words, all
contain only lower case alphabet symbols.
- True
- False
- None
Eg: a= true ❌
a=True ✅
How we can check the keywords
programmatically:
Import the module keyword and check the
kwlist attribute
(don’t worry about the meaning of module,
everything will be discussed step by step)
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert',
'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']
No comments:
Post a Comment