For Loop with Tuples

2 min read ·

A tuple is an ordered and immutable collection of elements. A for loop is used to iterate through each element of a tuple.

Basic Syntax

  • item holds one value at a time
  • Loop runs until the tuple ends

Simple Example


Tuple with Mixed Data Types


Using range() with Tuple Index


Conditional Logic with Tuple


Nested Tuple with for Loop


Tuple Unpacking in for Loop


Common Mistake

Caution

(5) is an integer, not a tuple. Use (5,) for single-element tuple.


Exercise