Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Aren't all iterables objects? You can turn any object into an iterable by adding through __iter__ method IIRC


Yes, but all objects are not iterables. If you list1.extend(object1) as the cheat sheet describes and object1 has no __iter__, it won't work. Likewise, you can iterate strings, so understanding the target of the iterable will be frustrating for list_of_strings.extend('newstring').

This is better described in python's native help documentation:

  $ python
  >>> help()
  >>> list
searching for extend via '/extend':

   |  extend(...)
   |      L.extend(iterable) -- extend list by appending elements from the iterable
Concise and correct.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: