About 149,000 results
Open links in new tab
  1. Type hinting tuples in Python - Stack Overflow

    Nov 28, 2017 · Just a note: if you need a tuple containing a variable number, you should think whether you should use a list instead. Maybe a tuple is still the right choice, but usually a list …

  2. python - Type hint for a tuple of variable length (variadic tuple ...

    Feb 18, 2019 · process_tuple really works with tuples and I use them as immutable lists of variable length. I haven't found any consensus on this topic on the internet, so I wonder how …

  3. python - How to access a field of a namedtuple using a variable …

    Jun 19, 2017 · How to access a field of a namedtuple using a variable for the field name? Asked 8 years, 6 months ago Modified 4 years, 4 months ago Viewed 58k times

  4. python - Add variables to tuple - Stack Overflow

    69 In Python 3, you can use * to create a new tuple of elements from the original tuple along with the new element.

  5. function - Ignore python multiple return value - Stack Overflow

    Say I have a Python function that returns multiple values in a tuple: def func(): return 1, 2 Is there a nice way to ignore one of the results rather than just assigning to a temporary variabl...

  6. python - Type hints when unpacking a tuple - Stack Overflow

    Aug 29, 2018 · Is it possible to use type hinting when unpacking a tuple? I want to do this, but it results in a SyntaxError: from typing import Tuple t: Tuple[int, int] = (1, 2) a: int, b: int = t # ^

  7. python - Multiple variables using tuple - Stack Overflow

    This doesn't store the tuple anywhere, so you'll be left with 4 variables with 4 different values. When you change the value of country, you change the value of this single variable, not of the …

  8. Ignore part of a python tuple - Stack Overflow

    Mar 2, 2012 · 89 If I have a tuple such as (1,2,3,4) and I want to assign 1 and 3 to variables a and b I could obviously say myTuple = (1,2,3,4) a = myTuple[0] b = myTuple[2] Or something like …

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

  10. python - Test if a variable is a list or tuple - Stack Overflow

    Feb 2, 2010 · Python uses "Duck typing", i.e. if a variable kwaks like a duck, it must be a duck. In your case, you probably want it to be iterable, or you want to access the item at a certain index.