0

As I am playing around with classes in Python, I thought the following might be useful. Given:

class NewClass:
    def __init__self():
        self.value = 1

new = NewClass()

Is there a way that by calling new, it would return the new.value of 1, rather than the class itself

<__main__.NewClass object at 0x7faa096d38d0>? 

I assume it might not be possible and people are against it, but I figured I'd ask anyway.

1 Answer 1

1
class NewClass():
    def __init__(self):
        pass

    def Ret(self):

         self.value = 1
         return self.value



new = NewClass().Ret()

print(new)
Sign up to request clarification or add additional context in comments.

1 Comment

return a list of variables with return (var1, var2, var3)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.