a=[[1,2,3],[4,5,6],[7,8,9]] b=[[1,1,1],[1,1,1],[1,1,1]] c=[[0,0,0],[0,0,0],[0,0,0]] for i in range(3): for j in range(3): c[i][j]=a[i][j] + b[i][j] for i in range(3): for j in range(3): print(c[i][j],end=' ') print() #function with parameters def add(a,b): c=a+b print(c) add(5,3) #function returning single value def add(a,b): return(a+b) print(add(2,3)) #function returning multiple value def area_peri(r): a=3.14*r*r p=2*3.14*r return(a,p) area_peri(5) class person: name='manohar' marks=150 def display(cls): print(cls.name) print(cls.marks) p1=person() p1.display() #encapsulation in python class stud: def __init__(self): self.id=16 self.name='sai' def display(self): print(self.id) print(self.name) p1=stud() p1.display() class A: a=1 b=2 def print1(cls): print(cls.a) print(cls.b) class B(A): c=3 def print2(cls): print(cls.c) b=B() b.print1() b.print2() class A: a=1 b=2 def print1(cls): print(cls.a) print(cls.b) class B(A): c=3 def print2(cls): print(cls.c) class C(B): pho=809959228 def print3(cls): print(cls.pho) c=C() c.print1() c.print2() c.print3() class student_details: def __init__(self): self.rno=10 self.name='shyam' def write(self): print(self.rno) print(self.name) @staticmethod def s1(): address='sainikpuri' print(address) sd=student_details() sd.write() sd.s1()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter