Python Classes and Object
1) Create a Class
To create a class, use the Keyword Class
Example:
Class Customer:
y=20
print customer()
Output
<Class '--main--.customer'>
2) Create Object
Example:
Class Customer:
y=20
object1=customer()
print(object1.y)
Output
20
3)The __init__ () is Function
The Example above are classes and objects in their simplest from, and are not really useful in real application. To Understand the meaning of classes we have to understand the build in __init__ Function all classes have a function called __init__(), Which is always executed when the class is begin initialized.
Example:
Class Customer:
def __init(self,name,age,phone,position)
self.name=name
self.age=age
self.phone=phone
self.year=position
object1=customer("Vannaro",40,333,"IT")
print(object1.name)
print(object1.age)
print(object1.phone)
print(object1.position)
Output
Vannaro
40
333
IT