Sum 19
Sum 19
Sum 19
LTD
DATE:08/06/2023
• Displaying Statement:
print("Hello World")
print(A)
print(B)
A=input("Enter No")
A,B=input("Enter No").split()
By writing this code using split() function we can take multiple inputs from a user at a
same time.
SUMAGO INFOTECH PVT.LTD
DATE:08/06/2023
• Print Statement Parameter:
1. end Parameter:
Example:
print("Hello ",end="")
print("World ",end="")
Output:
Hello World
2. sep Parameter:
Example:
print(08,06,2023,sep="/")
Output:
08/06/2023
• Class Task (Displaying Result)
Name,Std,Div=(input("Enter Name,Standard,Division ")).split()
eng=int(input("Enter Marks of English "))
maths=int(input("Enter Marks of Maths "))
sci=int(input("Enter Marks of Science "))
r="RESULT"
x=r.center(30)
print(x)
print("_"*40)
print("NAME: "+Name+" "+"STANDARD: "+Std+" "+"DIVISION:
"+Div)
print("English: ",eng)
print("Maths: ",maths)
print("Science: ",sci)
total=eng+maths+sci
per=((total)/300)*100
print("Total: ",total,"/300"," ","Percentage:",per,"%")
• Output:
Enter Name,Standard,Division SHAKAIB 12 B
Enter Marks of English 100
Enter Marks of Maths 100
Enter Marks of Science 100
RESULT
____________________________________________
NAME: SHAKAIB STANDARD: 12 DIVISION: B
English: 100
Maths: 100
Science: 100
Total: 300 /300 Percentage: 100.0 %
SUMAGO INFOTECH PVT.LTD
DATE:09/06/2023
• String Indexing Example:
String =”HELLO”
Print(String[0])
Output:
H
• String Slicing Example:
String1 =”HELLO”
Print(String1[0:4])
Output:
HELL
• String Concating Example:
String =”HELLO”
String1 =”World”
Print(String+String1)
Output:
HELLOWORLD
• Declaring and Displaying List Example:
lst=['ss',[2],[3,4]]
print(lst)
Output:
['ss',[2],[3,4]]
• Declaring Tuple and Displaying Example:
Tup=(1,2,3)
print(Tup)
Output:
(1,2,3)
• Declaring Set and Displaying Example:
set1={"Hello",1,1,"H",2}
print(set1)
Output:
{"Hello",1,1,"H",2}
SUMAGO INFOTECH PVT.LTD
DATE:12/06/2023
• Dictionary Example:
dic={1:"Shakaib","Shakaib":2,'List':{1,2,3},'Tuple':(1,2,3,4)}
print(dic)
print(dic[1])
print(dic.keys())
Output:
Hello
Hello
Hello
Hello
• While Loop Example:
count=0
while (count<5):
count+=1
print("Hello")
Output:
Hello
Hello
Hello
Hello
Hello
SUMAGO INFOTECH PVT.LTD
DATE:13/06/2023
• Flow control Example using if elif else:
elif c==a:
print("a and c is same")
else:
print("All are diffrent")
Output:
Enter value of a 10
Enter value of b 20
Enter value of c 30
DATE:14/06/2023
• Built-in Function Example:
1. abs():
integer = -20
print('Absolute value of -40 is:', abs(integer))
floating = -20.83
print('Absolute value of -40.83 is:', abs(floating))
Output:
Absolute value of -20 is: 20
Absolute value of -20.83 is: 20.83
2. all():
k= [1, 3, 4, 6]
print(all(k))
k = [0, False]
print(all(k))
k = [1, 3, 7, 0]
print(all(k))
k = [0, False, 5]
print(all(k))
k = []
print(all(k))
Output:
True
False
False
False
True
3. bin():
x = 10
y = bin(x)
print (y)
Output:
0b1010
SUMAGO INFOTECH PVT.LTD
DATE:15/06/2023
• Anonymous Function(Lambda) Example:
add = lambda a,b : a+b
sum=add(10,20)
print(sum)
Output:
30
• Special Function Exapmles:
1. Filter():
def even (n):
if n%2==0:
return True
else:
return False
odd = lambda n : n%2!=0
lst=[1,4,23,34,2,4,5,6,646,234]
even=list(filter(even,lst))
even=list(filter(lambda n : n%2!=0,lst))
print(even,type(even))
Output:
[1, 23, 5] <class 'list'>
2. reduce():
import functools
big=[1,2033,202,321,13,12,1233]
biggest=functools.reduce(lambda x,y:x if x>y else y,big)
print(biggest)
lst=[1,2,3,4,5,6,7,8,9,]
for i in range(1,len(lst),2):
print(lst[i])
Output:
2033
2
4
6
8
SUMAGO INFOTECH PVT.LTD
DATE:16/06/2023
• Inheritance Example:
class Vehicle:
def __init__(self,name,maxspeed,millage) :
self.name=name
self.maxspeed=maxspeed
self.millage=millage
def seating_capacity(self,capacity):
self.seating_capacity=car
return "The seating capacityof a
{self.name} is {capacity} passenger"
class car(Vehicle):
car=Vehicle("Bus",186,12)
print("Car
name=",car.name,"Maxspeed=",car.maxspeed,"Millage
=",car.millage)
class bus(Vehicle):
pass
obj=Vehicle("Bus",186,12)
obj.seating_capacity(50)
Output:
DATE:19/06/2023
• Encapsulation Example:
class Base:
def __init__(self):
self._a = 2
class Derived(Base):
def __init__(self):
Base.__init__(self)
print("Calling protected member of base class: ",
self._a)
self._a = 3
print("Calling modified protected member outside
class: ",
self._a)
obj1 = Derived()
obj2 = Base()
print("Accessing protected member of obj1: ", obj1._a)
print("Accessing protected member of obj2: ", obj2._a)
Output:
Calling protected member of base class: 2
Calling modified protected member outside class: 3
Accessing protected member of obj1: 3
Accessing protected member of obj2: 2