Why python for loops don't default to one iteration for single objects?


Python cannot iterate over an object that is not 'iterable'. The 'for' loop construct in python calls inbuilt functions within the iterable data-type which allow it to extract elements from the iterable.

Since non-iterable data-types don't have these methods, there is no way to extract elements from them. And hence for loops ignore them.

Updated on: 30-Jul-2019

91 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements