Skip to content

iamkirankumaryadav/Keywords

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Keywords

Python Keywords are Predefined

False, True

  • Boolean Data Types
False == (1 > 2) ,True == (2 > 1)

None

  • Empty Value Constant
def func():
  x = 2

func() == None 
--------------
True

and, or, not

Logical Operators

  1. x and y : both x and y must be True.
  2. x or y : either x or y must be True.
  3. not x : x must be False.
x, y = True, False

print(x and y)
print(x or y)
print(not x )
Output : 
False
True
False

break

  • Premature Loop Ending.
while(True):
    break 
print('hello world')
Output : 
hello world

class, def

  • class : Create New Class
  • def : Define a New Function or Class Method.
class Car:
    def __init__(self, Name, Company, Model, Type):
        self.Name = Name
        self.Company = Company
        self.Model = Model
        self.Type = Type
        
    def Details(self):
        return f'🚗 Tata Motors\nCompany : {self.Company}\nName    : {self.Name}\nModel   : {self.Model}'
C = Car(Name = 'Safari', 
        Company = 'Tata',
        Model = 'ZX',
        Type = 'SUV')

print(C.Details())
Output :
🚗 Tata Motors
Company : Tata
Name    : Safari
Model   : ZX

if, elif, else

  • Conditional Program Execution.
x = int(input('Enter the Value : '))
if x > 3: 
    print('Big')
elif x == 3: 
    print('Medium')
else:
    print('Small')
Output : 
Enter the Value : 1
Small

for, while

  • Creating Loops
for i in [0,1,2]:
    print(i)
j = 0
while j < 3:
    print(j)
    j = j + 1
Output :
0
1
2

in

  • Check for Presence in Sequence.
5 in [5,10,15]
Output :
True

is

  • Check for Similary.
x = y = 3
x is y
Output :
True

lambda

  • Create Anonymous Function
x = (lambda x : x + 3)
x(2)
Output :
5

return

  • Result of Function
def increase(x):
    return x + 1
    
increase(99)    
Output :
100

About

Predefined Python Keywords

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published