About 16,700,000 results
Open links in new tab
  1. Python - Loop Tuples - W3Schools

    You can loop through the tuple items by using a while loop. Use the len() function to determine the length of the tuple, then start at 0 and loop your way through the tuple items by referring to …

  2. How to create tuple with a loop in python - Stack Overflow

    Feb 17, 2018 · Edit: Adapting juanpa.arrivillaga's comment, if you want to stick with a loop, this is the right solution: a = [(1,1,1)] for i in range (2,10): a.append((i,i,i)) a = tuple(a)

  3. Iterate over a tuple in Python - GeeksforGeeks

    Oct 11, 2024 · Below is an example on how to iterate over a tuple using a for loop. Python t = ( 'red' , 'green' , 'blue' , 'yellow' ) # iterates over each element of the tuple 't' # and prints it for …

  4. How to Iterate Through Tuples in Python? - Python Guides

    Dec 12, 2024 · In this tutorial, I have explained various ways to iterate through tuples in Python. We covered using for loops, while loops, the enumerate() function, iterating over a list of …

  5. Python Tuple For Loop

    Python Tuple For Loop - The tuple variable returns an iterator and when used with Python For Loop, you can access each item of the tuple during respective iteration. In this tutorial, we …

  6. 3.2. Loops and Tuples — Hands-on Python Tutorial for Python 3

    Jan 5, 2020 · Making a tuple is another way to make several items into a single object. You can refer to individual parts with indexing, like with lists, but a more common way is with multiple …

  7. 4 ways to loop through a tuple in Python - Sling Academy

    Feb 12, 2024 · Using a For Loop. The for loop is the most straightforward method to iterate through items in a tuple. It is clean, readable, and efficient for most use cases. Steps: Start by …

  8. How to Loop Through a Tuple in Python - tutorialsarena.com

    Learn how to iterate over tuple elements and display them with simple examples. You can loop through the items in a tuple using a for loop: thistuple = ("apple", "banana", "cherry") for x in …

  9. python - How are tuples unpacked in for loops? - Stack Overflow

    You can combine the for index,value approach with direct unpacking of tuples using ( ). This is useful where you want to set up several related values in your loop that can be expressed …

  10. Python Loops and Tuples - Online Tutorials Library

    Loop Through Tuple Items with For Loop. A for loop in Python is used to iterate over a sequence (like a list, tuple, dictionary, string, or range) or any other iterable object. It allows you to …

Refresh