Python Forum
problem with function return value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with function return value
#8
You are missing basic understanding how class works.
So read more about it.
Quote:I dont know what the function anything will return
It's not called a function when it belong to class,it's now a method.
You should not have variables outside the class,
these should be arguments that is given to the class.
Just to write something that make more sense,in the way class work.
Not changing anything to method anything which could be wrong.
class xyz:
    def anything(self, anything, somethingelse, a):
        if something < somethingelse:
            if a == 10:
                return something
            else:
                return somethingelse
        elif a > somethingelse:
            return something
        else:
            return something

    def calculations(self, any_obj):
        x = any_obj + 5
        y = any_obj + 10
        return x, y

object1 = xyz()
something = 10
somethingelse = 0
a = 2
any_obj = object1.anything(something, somethingelse, a)
print(object1.calculations(any_obj)) #(15, 20)
Reply


Messages In This Thread
RE: problem with function return value - by Ofnuts - Sep-22-2016, 03:01 PM
RE: problem with function return value - by wavic - Sep-22-2016, 03:26 PM
RE: problem with function return value - by Ofnuts - Sep-22-2016, 03:45 PM
RE: problem with function return value - by nilamo - Sep-22-2016, 03:47 PM
RE: problem with function return value - by snippsat - Sep-22-2016, 03:54 PM
RE: problem with function return value - by nilamo - Sep-23-2016, 03:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  nested function return MHGhonaim 2 675 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  return next item each time a function is executed User3000 19 2,460 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  function return boolean based on GPIO pin reading caslor 2 1,246 Feb-04-2023, 12:30 PM
Last Post: caslor
  Stock Return calculation problem LFin 10 2,248 Sep-26-2022, 04:28 PM
Last Post: deanhystad
  return vs. print in nested function example Mark17 4 1,819 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  How to invoke a function with return statement in list comprehension? maiya 4 2,947 Jul-17-2021, 04:30 PM
Last Post: maiya
  Function - Return multiple values tester_V 10 4,621 Jun-02-2021, 05:34 AM
Last Post: tester_V
  Get return value from a threaded function Reverend_Jim 3 17,367 Mar-12-2021, 03:44 AM
Last Post: Reverend_Jim
  Return not exiting function?? rudihammad 3 5,393 Dec-01-2020, 07:11 PM
Last Post: bowlofred
  Why does my function return None? vg100h 3 2,270 Oct-29-2020, 06:17 AM
Last Post: vg100h

Forum Jump:

User Panel Messages

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