About 4,070,000 results
Open links in new tab
  1. Python class returning value - Stack Overflow

    Use __new__ to return value from a class. As others suggest __repr__,__str__ or even __init__ (somehow) CAN give you what you want, But __new__ will be a semantically better solution …

  2. Get the return value from a function in a class in Python

    Class functions must always take one parameter, self. That's because when you call a function within the class, you always call it with the class name as the calling object, such as: scoreObj …

  3. How to return the class instance in a function in Python

    May 25, 2020 · I have changed your code to show how you can return instances: class Dog: # constructor method def __init__(self, name, age): self.name = name self.age = age # three …

  4. Python Return Class From Function – Be on the Right Side of

    Jul 27, 2023 · In Python, you can return class objects from functions just like any other data type. This can be useful in situations where you need to create an instance of a specific class based …

  5. Get Return Value from Function in a Class in Python

    def getScore(self): return self.score. def getEnemies(self): return self.num_enemies. def getLives(self): return self.num_lives. Learn how to get the return value from a function within a …

  6. 9. ClassesPython 3.13.3 documentation

    2 days ago · Python classes provide all the standard features of Object Oriented Programming: the class inheritance mechanism allows multiple base classes, a derived class can override …

  7. Return type of function returning a class - Python Help

    May 27, 2022 · I have a function that returns a class created within the function, so something like this: def foo(a, b): class Bar: def __init__(self, func): ... return Bar

  8. The Python return Statement: Usage and Best Practices

    In this tutorial, you’ll learn that: You use return to send objects from your functions back to the caller code. You can use return to return one single value or multiple values separated by …

  9. Python return statement - GeeksforGeeks

    Dec 10, 2024 · In Python, functions are first-class citizens, meaning you can return a function from another function. This is useful for creating higher-order functions. Here's an example of …

  10. Returning a function from a function – Python | GeeksforGeeks

    Mar 19, 2025 · Returning functions from functions is a versatile and powerful feature in Python. It can be used in various scenarios, such as: Callbacks: Functions can be returned to be called …

Refresh