About 4,700,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. 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 …

  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 …

  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. python: return, return None, and no return at all -- is there any ...

    Either all return statements in a function should return an expression, or none of them should. If any return statement returns an expression, any return statements where no value is returned …

  6. python - How to get the return value from a thread? - Stack …

    Mar 18, 2023 · 333 In Python 3.2+, stdlib concurrent.futures module provides a higher level API to threading, including passing return values or exceptions from a worker thread back to the main …

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

  8. python - how to return index of a sorted list? - Stack Overflow

    Oct 21, 2011 · I need to sort a list and then return a list with the index of the sorted items in the list. For example, if the list I want to sort is [2,3,1,4,5], I need [2,0,1,3,4] to be returned. This …

  9. python - How can I get the return value of a function passed to ...

    Dec 1, 2016 · In the example code below, I'd like to get the return value of the function worker. How can I go about doing this? Where is this value stored? Example Code: import …

  10. python - if statement to one line with return - Stack Overflow

    Jan 18, 2017 · 10 This question already has answers here: Is it possible to write single line return statement with if statement? (5 answers)