Python Keywords are Predefined
- Boolean Data Types
False == (1 > 2) ,True == (2 > 1)EmptyValue Constant
def func():
x = 2
func() == None
--------------
TrueLogical Operators
- x and y : both x and y must be True.
- x or y : either x or y must be True.
- 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- Premature Loop Ending.
while(True):
break
print('hello world')Output :
hello worldclass: Create New Classdef: 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- 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- Creating Loops
for i in [0,1,2]:
print(i)j = 0
while j < 3:
print(j)
j = j + 1Output :
0
1
2- Check for Presence in Sequence.
5 in [5,10,15]Output :
True- Check for Similary.
x = y = 3
x is yOutput :
True- Create Anonymous Function
x = (lambda x : x + 3)
x(2)Output :
5- Result of Function
def increase(x):
return x + 1
increase(99) Output :
100