Mar-16-2020, 08:11 AM
(This post was last modified: Mar-16-2020, 08:12 AM by javiertzr01.)
The way to use classes are via objects. This means that Employee is just like a name for your class, like a title. The way you use the class is by initializing an object. This is done by this code:
I'll give you another example:
Lets say I create a class called Money with initializer method def __init__(self, value)
And lets say I create a method called deposit() that deposits the money
I will initialize an object called Five dollar note by doing Five_Dollar_Note = Money(5) #Assigning value of 5
I will also initialize another object called Ten dollar note by doing Ten_Dollar_Note = Money(10) #Assigning value of 10
To use my deposit function, I will do Five_Dollar_Note.deposit() or Ten_Dollar_Note.deposit() instead of Money.Deposit()
because you can deposit a 5 dollar note, or a 10 dollar note, but you don't deposit "money". However, 5 dollar note and 10 dollar note are both "money"
I don't know if I did a good job explaining it but I hope you understand.
empl_1 = Employee("Suman Palisetty", 37). This makes empl_1 an object from the class Employee, meaning to say that empl_1 is able to use the methods defined in the Employee class. However, the Employee class itself is not meant to be called to use a method.
I'll give you another example:
Lets say I create a class called Money with initializer method def __init__(self, value)
And lets say I create a method called deposit() that deposits the money
I will initialize an object called Five dollar note by doing Five_Dollar_Note = Money(5) #Assigning value of 5
I will also initialize another object called Ten dollar note by doing Ten_Dollar_Note = Money(10) #Assigning value of 10
To use my deposit function, I will do Five_Dollar_Note.deposit() or Ten_Dollar_Note.deposit() instead of Money.Deposit()
because you can deposit a 5 dollar note, or a 10 dollar note, but you don't deposit "money". However, 5 dollar note and 10 dollar note are both "money"
I don't know if I did a good job explaining it but I hope you understand.