Python Forum
Using one method's result for another method in the same Class?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using one method's result for another method in the same Class?
#4
Note that you can turn get_area into property using @property decorator.

class Rectangle:
    def __init__(self, width, height):
        self.width = width
        self.height = height


    @property 
    def area(self):
        return self.width * self.height

rect = Rectangle(10, 2)
print(rect.area)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Using one method's result for another method in the same Class? - by buran - Sep-13-2020, 06:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Accessing method attributes of python class Abedin 6 583 Apr-14-2025, 07:02 AM
Last Post: buran
  __eq__ method related problem Tsotne 6 844 Mar-09-2025, 03:48 PM
Last Post: Tsotne
  Changing client.get() method type based on size of data... dl0dth 1 679 Jan-02-2025, 08:30 PM
Last Post: dl0dth
  Error in the method "count" for tuple fff 2 794 Nov-24-2024, 03:29 AM
Last Post: fff
  Trying to understand method Giri234 1 682 Oct-04-2024, 02:10 AM
Last Post: deanhystad
  Destructor method adding in string chizzy101010 3 905 Sep-03-2024, 12:31 PM
Last Post: chizzy101010
  Difference between method and attribute holding a function ulrich 2 902 Jun-30-2024, 08:35 AM
Last Post: snippsat
  comtypes: how to provinde a list of string to a COM method zalanthas 0 912 Jun-26-2024, 01:27 PM
Last Post: zalanthas
Question No disconnect method for snowflake.connector ? Calab 0 809 Jun-11-2024, 09:42 PM
Last Post: Calab
  Which method name would you choose? Gribouillis 7 1,723 May-30-2024, 07:05 AM
Last Post: buran

Forum Jump:

User Panel Messages

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