Ad Code

Responsive Advertisement

Keywords in Python | Learn Python For Free

Keywords in Python | Learn Python For Free

What are Keywords in Python | Keywords | Keywords in Python |  Uses of Keywords | Use of Python Keywords .




Keywords in Python

Keywords are reserved words used by Python interpreter to recognize the structure of a program.

As these words have specific meaning for interpreter, they cannot be used as variables names or for any other purpose.

For checking displaying the list of Keywords available in Python, we have to write the following two statements:

Import Keyword
print(Keywords.kwlist)

Watch the video how to import Keyword in Python






Note:  All the Keywords in Python are in lowercase except False, None and True which starts with the capital letters.

Uses of Keywords:

False-:       It is used in case If the comparison is wrong.
For example-:
False-:
n=6<3
if n is False:
    print("hello")
else:
   print("no")
Output-:hello

None-:       This signifies the absence of the value.
For example-:
>>> value1=10
>>> value2= None
>>> value1
10
>>> value2
>>>              

True-:        it is used in case If the condition is true.
For example-:
n=6 < 3
if n is False:
    print("hello")
else:
   print("no")
Output-: hello

And -: If fist condition is true and second condition is false than the whole condition is false. It works on the Boolean variable.

If the condition is true than the value is 1, and if wrong than the value is 0.

So if one condition is true and other is false then,

1 x 0 = 0 # means whole condition is false.

If one condition is true and other is also true then,

1 x 1 = 1 # means whole condition is true.

For example -:
if 5>4 and 5<6 :
    print("right")
else:
   print("wrong")
Output-: wrong

Or -:
If any of the one condition is true then the whole condition is true, and if both the conditions are true and both the both are false then the final condition becomes true and false respectively.

If the condition is true than the value is 1, and if wrong than the value is 0.

So if one condition is true and other is false then,

1 + 0 = 1 # means whole condition is true.

If one condition is true and other is also true then,

1 + 1 = 1 # means whole condition is true.

Similarly you can do it for false.

Not-:  It allows us to check if any data is present in a container or variable or not .
For example-:
if 3 not in [ 1,2,3,4,5 ]:
   print("right")
else:
   print("wrong")
Output-: wrong

Post a Comment

0 Comments