python reserved words


PYTHON RESERVED WORDS OR KEYWORDS
What do you mean reserved?
Means to be kept or set apart for some particular use or purpose.

like the same way in programming languages it contains keywords that have particular meaning and for a particular purpose.
i.e., these words represent meaning or functionality such type of words is called reserved words.

present in python 3.9 has 36 keywords, which will increase over time, with the addition of newer keywords.
They are

['False',  'None',  'True',  '__peg_parser__',  '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']

Note:
All the keywords are denoted with characters only i.e., in lower case letters, and only three words are started with upper capital letters they are True, False, None and instead of this if you use symbols or digits it throws an error. 

example:
a = true
print(a)
output:
Traceback (most recent call last):
  File "D:\practical\one.py", line 318, in <module>
    a = true
NameError: name 'true' is not defined

so true or false or none should be capital only ie.,
example:
a = True
print(a)
output: True
note:
Switch and do while concepts are not applicable in python.

To check the keywords
import keyword
a = keyword.kwlist
print(a)
output:
['False', 'None', 'True', '__peg_parser__',
'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']

Remember that we cant use the keywords as an identifier, if you use it then it will get an error.
example:
def = "pyhton"
print(def)
Output:
    def = "pyhton"
        ^
SyntaxError: invalid syntax


note:
if you like it then comment and share it and dont forget to subscribe

No comments:

Post a Comment