List of Python Keywords
List of Python Programming Keywords
Like other programming languages for Python has got certain reserved words, which can not be used as variable names.
The most important Python keywords are the following.
and |
FALSE |
nonlocal |
as |
finally |
not |
assert |
for |
or |
break |
from |
pass |
class |
global |
raise |
continue |
if |
return |
def |
import |
TRUE |
del |
in |
try |
elif |
is |
while |
else |
lambda |
with |
except |
None |
yield |
Let's continue to learn more in detail about keywords and their uses.
Keyword | Description | Code example
---------------------------------------------------------------------------
False,True Data values from the data type Boolean False == ( 5 > 3 )
True == ( 20 > 10 )
---------------------------------------------------------------------------
and,or,not Logical operators:
(x and y) → both x and y must be True x, y = True , False
(x or y) → either x or y must be True (x or y) == True # True
(x and y) == False # True
( not x) → x must be false (not y) == True # True
---------------------------------------------------------------------------
break Ends loop while ( True ):
break # no infinite loop
print( "hello world" )
--------------------------------------------------------------------------
continue Finishes current loop while ( True ):
continue
print( "83" ) # dead code
class to create a class class: person:
--------------------------------------------------------------------------
def Defines a new function or def my_function():
class method. print("Hello from a function")
my_function()
--------------------------------------------------------------------------
if Conditional program x = 12
if x > 10:
print("YES")
---------------------------------------------------------------------------
elif Conditional program x = 12
if x > 10:
print("YES")
else:
print("No")
---------------------------------------------------------------------------
else Conditional program if x > 25 :
print( "Big" )
elif x == 25 :
print( "Medium" )
else :
print( "Small" )
-------------------------------------------------------------------------
for create a for loop. for i in [ 0 , 1 , 2 ]:
print(i)
while create a while loop. j=0
while j<3:
print(j)
j=j+1;
------------------------------------------------------------------------
in Checks whether element is mobile=["Nokia", "Apple","Samsung"]
in sequence if "Apple" in mobile:
print("Yes")
for x in mobile:
print(x)
--------------------------------------------------------------------------
is Checks whether both x=y=["Nokia", "Apple","Samsung"]
element point to the print(x is y) #True
same object y = "Apple"
print(x is y) #False
--------------------------------------------------------------------------
None Empty value constant def f () :
x = 2
f() is None # True
--------------------------------------------------------------------------
lambda Function with no name (lambda x: x + 3)(3)
(anonymous) #returns value 6
--------------------------------------------------------------------------
return
Terminates function execution and passes the execution flow to the caller.
An optional value after the return keyword specifies the result.
def incrementor (x) : #incrementor is function here
return x + 1
incrementor( 4 ) # returns 5
------------------------------------------------------------------------
No comments