About 118,000 results
Open links in new tab
  1. python - Is it pythonic for a function to return multiple values ...

    Using the tuple () built-in: tuple () or tuple (iterable) Functions should serve single purpose Therefore they should return a single object. In your case this object is a tuple. Consider tuple as an ad-hoc …

  2. python - How to annotate types of multiple return values ... - Stack ...

    Oct 21, 2016 · Only the Tuple type lets you specify a fixed number of elements, each with a distinct type. You really should be returning a tuple, always, if your function produces a fixed number of return …

  3. Python type hints for function returning multiple return values

    Sep 25, 2019 · 12 Multiple return values in python are returned as a tuple, and the type hint for a tuple is not the tuple class, but typing.Tuple.

  4. return - Alternatives for returning multiple values from a Python ...

    For Python 2.6 and up, a named tuple provides a useful way of easily creating these container classes, and the results are "lightweight and require no more memory than regular tuples".

  5. Returning a Tuple in Python function - Stack Overflow

    Sep 12, 2013 · I just mocked up this function, replacing take_turn and other undefined things with lambda *a: 1. It returns a tuple. (There's no way this function shown is returning anything other than a …

  6. python - Getting one value from a tuple - Stack Overflow

    You can write i = 5 + tup()[0] Tuples can be indexed just like lists. The main difference between tuples and lists is that tuples are immutable - you can't set the elements of a tuple to different values, or add …

  7. python - Returning None or a tuple and unpacking - Stack Overflow

    Apr 21, 2017 · 1 OK, I would just return (None, None), but as long as we are in whacko-land (heh), here is a way using a subclass of tuple. In the else case, you don't return None, but instead return an …

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

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

  9. Python: Return tuple or list? - Stack Overflow

    Nov 17, 2011 · 14 I have a method that returns either a list or a tuple. What is the most pythonic way of denoting the return type in the argument?

  10. python - Should a return statement have parentheses? - Stack Overflow

    Remember that the return keywords returns the result of a statement. So if you only use , in your multiple assignment statements and tuple constructions, omit the (), but if you use () for value …