Python Forum
Trying to understand the python code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to understand the python code
#3
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:
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.
Reply


Messages In This Thread
RE: Trying to understand the python code - by buran - Mar-15-2020, 10:20 AM
RE: Trying to understand the python code - by javiertzr01 - Mar-16-2020, 08:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to understand the meaning of the line of code. jahuja73 0 401 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Understand what it means that everything in Python is an object... bytecrunch 8 3,962 Mar-19-2021, 04:47 PM
Last Post: nilamo
  Understand order of magnitude performance gap between python and C++ ThelannOryat 4 2,806 Mar-17-2021, 03:39 PM
Last Post: ThelannOryat
  Unable to understand how given code takes a fixed input value, without inputting. jahuja73 4 2,825 Jan-28-2021, 05:22 PM
Last Post: snippsat
  Don't understand example code from a textbook lil_fentanyl 1 1,901 Jan-25-2021, 07:02 PM
Last Post: nilamo
  Unable to understand a statement in an existing code ateestructural 1 2,297 Aug-01-2020, 09:38 PM
Last Post: deanhystad
  I couldn't understand the output of the below code ravich129 1 1,983 Dec-12-2019, 06:24 AM
Last Post: sandeep_ganga
  I do not understand why my python looks different from tutorials. noodlespinbot 2 5,274 Oct-12-2019, 09:56 PM
Last Post: noodlespinbot
  I dont understand bytes in python. blackknite 3 4,162 Oct-02-2019, 07:39 PM
Last Post: Gribouillis
  can you understand why this code prints None? arcbal 2 2,832 Mar-13-2019, 02:57 AM
Last Post: arcbal

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020