About 50 results
Open links in new tab
  1. python - What is the purpose of the return statement? How is it ...

    What does the return statement do? How should it be used in Python? How does return differ from print? See also Often, people try to use print in a loop inside a function in order to see multiple ...

  2. How to specify multiple types using type-hints - Stack Overflow

    Sep 20, 2025 · I have a function in python that can either return a bool or a list. Is there a way to specify the types using type hints? For example, is this the correct way to do it? def foo(id) -> list or b...

  3. python - It is more efficient to use if-return-return or if-else-return ...

    Feb 8, 2012 · Since the return statement terminates the execution of the current function, the two forms are equivalent (although the second one is arguably more readable than the first). The efficiency of …

  4. python: return, return None, and no return at all -- is there any ...

    Note that there's a stylistic difference. return None implies to me that the function sometimes has a non- None return value, but at the location of return None, there is no such return value. Writing no return …

  5. python - How do I get ("return") a result (output) from a function? How ...

    We can make a tuple right on the return line; or we can use a dictionary, a namedtuple (Python 2.6+), a types.simpleNamespace (Python 3.3+), a dataclass (Python 3.7+), or some other class (perhaps …

  6. How can I return two values from a function in Python?

    I would like to return two values from a function in two separate variables. What would you expect it to look like on the calling end? You can't write a = select_choice(); b = select_choice() because that …

  7. Is there a way to return literally nothing in python?

    There is no such thing as "returning nothing" in Python. Every function returns some value (unless it raises an exception). If no explicit return statement is used, Python treats it as returning None. So, …

  8. python - Return a default value if a dictionary key is not available ...

    The constructor takes a function that is called with the key and should return the value for the dictionary. This value is then stored and retrieved from the dictionary next time.

  9. python - what is the need to use return 1 or -1 in the end of a ...

    Jul 28, 2020 · 0 Generally, a return statement is used to give a value back to the caller of the function. In your code for instance: you return 1 if the if condition checks out, and return -1 if the condition is not …

  10. Is it possible to not return anything from a function in python? (What ...

    Is it possible to not return anything from a function in python? (What happens if the function reaches the end without `return`ing?) Asked 14 years ago Modified 4 months ago Viewed 118k times