Which fix removes the bug?
colors = ('red')
for c in colors:
print(c) # expected: red
- Add a comma:
('red',) - Use
list('red')there - Write
tuple('red') - Use
str('red')here
Parentheses alone do not make a tuple, so colors is a string and the loop walks its letters.
Play Problem Solving ▸