Wednesday, 2 January 2019

Python Reserved Keywords



Reserved Keywords

There are 33 reserved words are available in Python.
True,False,None
and,or,not,is
if,else,elif
while,for,break,continue,return,in,yield
try,except,finally,raise(To throw custom exceptions similar like java throw),assert(For debugging purposes)
import,from,as(To create alias),class,def(To declare method),pass(Not going to do anything)
global(To declare global variable),nonlocal(To declare local variable),lambda(To create anonymous funtions)
del(To delete a variable or method or class),with(In File handling will be used)

Note:
1)All reserved words contain only alphabets.
2)Except first 3 contain lower case alphabets.

How to check reserved keywords in Python using Python Program?

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', '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']

No comments:

Post a Comment