Python Forum
When to decide whether or not to have an argument in a class method?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
When to decide whether or not to have an argument in a class method?
#2
to the particular error in your code (the first one) you should amend the code as follows
 
    def price(self, otherSide):
        if otherSide**3 < self.volume():
            return "The house is more expensive" 
 
however there are many flaws in your code. some of them:
- first of all price method will return None if the volume of other house has bigger/same volume
- method name (price) is misleading. one would expect it to return/calculate price. more appropriate name should be used
- it's more logical to take as argument another house object, not side size
Reply


Messages In This Thread
RE: When to decide whether or not to have an argument in a class method? - by buran - Oct-29-2017, 03:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 305 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  super() and order of running method in class inheritance akbarza 7 834 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
  Using one child class method in another child class garynewport 5 1,683 Jan-11-2023, 06:07 PM
Last Post: garynewport
  i want to use type= as a function/method keyword argument Skaperen 9 1,973 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,351 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  class, attribute and method Frankduc 9 2,548 Feb-27-2022, 09:07 PM
Last Post: deanhystad
  Subclass initialized property used in parent class method. Is it bad coding practice? saavedra29 5 1,883 Feb-07-2022, 07:29 PM
Last Post: saavedra29
  Class Method to Calculate Age Doesn't Work gdbengo 1 1,738 Oct-30-2021, 11:20 PM
Last Post: Yoriz
Question How to pass a method as argument in an another method? anilanvesh 6 2,804 Sep-30-2021, 10:18 PM
Last Post: deanhystad
  anonymous method in a class Skaperen 8 3,665 May-23-2021, 11:17 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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