About 2,310,000 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 …

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

    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 …

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

    Using return None This tells that the function is indeed meant to return a value for later use, and in this case it returns None. This value None can then be used elsewhere. return None is never …

  4. 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() …

  5. Does every Python function have to return at the end?

    Mar 10, 2017 · Long answer: The return statement is not required in Python, and reaching the end of the function's code without a return will make the function automatically return None …

  6. In Python, if I return inside a "with" block, will the file still close?

    Mar 27, 2012 · Consider the following: with open (path, mode) as f: return [line for line in f if condition] Will the file be closed properly, or does using return somehow bypass the context …

  7. python - How can I use `return` to get back multiple values from a …

    Jul 4, 2020 · How can I use `return` to get back multiple values from a loop? Can I put them in a list? Asked 8 years, 6 months ago Modified 3 years ago Viewed 189k times

  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. 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 …

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

    A new Python checker was added to warn about inconsistent-return-statements. A function or a method has inconsistent return statements if it returns both explicit and implicit values ...