Sum 19

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

SUMAGO INFOTECH PVT.

LTD

DATE:08/06/2023
• Displaying Statement:

print("Hello World")

This code will Display Hello World on the terminal.


• Declaring Variable:
A=5
B=10
by writing this code I have assigned values to variable a & b
• Displaying Variable:

print(A)
print(B)

This code will Display value stored in variable a & b.

• Taking Input from User:

A=input("Enter No")

Using this code we can take input from user.

• Taking Multiple Inputs from User:

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:

{1: 'Shakaib', 'Shakaib': 2, 'List': {1, 2, 3}, 'Tuple': (1, 2, 3, 4)}


Shakaib
dict_keys([1, 'Shakaib', 'List', 'Tuple'])
• For Loop Example:
lst=[1,2,3,4]
for x in lst:
print("Hello")
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:

a=int(input("Enter value of a "))


b=int(input("Enter value of b "))
c=int(input("Enter value of c "))
if a==b==c:
print("All are same")
elif a==b:
print("a and b is same")
elif a==c:
print("a and c is same ","B is different")

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

All are different


SUMAGO INFOTECH PVT.LTD

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:

Car name= Bus Maxspeed= 186 Millage= 12


SUMAGO INFOTECH PVT.LTD

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

You might also like