
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 …
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 …
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 …
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) …
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() …
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, 7 months ago Modified 3 years, 1 month ago Viewed 189k times
how to return values in a python dictionary - Stack Overflow
Feb 20, 2023 · A Python dictionary is a collection of Key-Value pairs, meaning that you have several items each with an "index" or "name" (the key) and a value (anything, in your case, lists)
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 …
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 …
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 ...