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 
# from w  w  w.j  a va2  s.  co m
for x in T: print(x, end=' ')     # Iterate over a tuple

Result

Related Example