Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

In Python, which types of iterable structures can the for loop syntax be used with?
Options
A Only lists and tuples.
B Only sets and dictionaries.
C Any type of iterable structure, such as a list, tuple, string, set, dictionary, or file.
Correct Answer
D Only user-defined classes.
Correct Answer

Option C is the correct answer.

Detailed Explanation

Page 74 states: 'The for-loop syntax can be used on any type of iterable structure, such as a list, tuple str, set, dict, or file'. This highlights the versatility of Python's for loop.

Hint

The 'for' loop in Python is designed to work with a broad category of data structures that can be 'iterated' over.

Question Info