Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
suyashi29
GitHub Repository: suyashi29/python-su
Path: blob/master/Python core/Classes & Objects.ipynb
3074 views
Kernel: Python 3

Classes and Objects

class P1: x="HI" print(P1.x)#Tell about status of class.
#Class variables class P2: name="RAM" age = 29 print("NAME is %s and age is %d"%(P2.name,P2.age))
#Class &Objects class Phone(): Color=" " Price =00 Type=" " ob1=Phone()#Creation of objects and assinging it to class phone. ob2=Phone() ob1.Color="RED" ob1.Price=10000 ob1.Type="Nokia" ob2.Color="Black" ob2.Price=12000 ob2.Type="Asus" print("This is a %s phone of %s color and its price is %drs"%(ob1.Type,ob1.Color,ob1.Price)) print("This is a %s phone of %s color and its price is %drs"%(ob2.Type,ob2.Color,ob2.Price))
class X: def __init__(self,name,age): self.name=name self.age=age ob=X("ran",18) print(ob.name , ob.age)
# dictionary from an class's fields. class dObj(): def __init__(self): self.x = 'age' self.y = 'name' self.z = 'Gender' def do(self): pass d = dObj() print(d.__dict__)