Python - For each item in sequence

Introduction

Any sequence works in a for.

For example, for loops work on strings and tuples:

Demo

S = "this is a test" 
T = ("and", "I'm", "okay") 

for x in S: print(x, end=' ')     # Iterate over a string 
#   w w  w.j  a v  a2  s .c o  m
for x in T: print(x, end=' ')     # Iterate over a tuple

Result

Related Example