Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

I hope iI can make a useful supplement to this question, if. If your list storestores a specific type object, for example Info, Herehere is a situation that extend method is not suitable,: In a forfor loop and and generate a Infogenerating an Info object every time and using extendextend to store it into your list, it will failed,fail. The exception is like below:

TypeError: 'Info' object is not iterable

TypeError: 'Info' object is not iterable

butBut if you use the append method, the result is OK. Because every time using extendthe extend method, it will always treat it as a list or any othersother collection type and, iterate it, and place it after the previous list.Specific A specific object can not be iterated, obviously.

hope i can make a useful supplement to this question, if your list store a specific type object, for example Info, Here is a situation that extend method is not suitable, In a for loop and and generate a Info object every time and using extend to store it into your list, it will failed, exception like below:

TypeError: 'Info' object is not iterable

but if you use append method, result is OK. Because every time using extend method, it will always treat it as a list or any others collection type and iterate it and place it after the previous list.Specific object can not be iterated obviously.

I hope I can make a useful supplement to this question. If your list stores a specific type object, for example Info, here is a situation that extend method is not suitable: In a for loop and and generating an Info object every time and using extend to store it into your list, it will fail. The exception is like below:

TypeError: 'Info' object is not iterable

But if you use the append method, the result is OK. Because every time using the extend method, it will always treat it as a list or any other collection type, iterate it, and place it after the previous list. A specific object can not be iterated, obviously.

Source Link
Crabime
  • 682
  • 13
  • 30

hope i can make a useful supplement to this question, if your list store a specific type object, for example Info, Here is a situation that extend method is not suitable, In a for loop and and generate a Info object every time and using extend to store it into your list, it will failed, exception like below:

TypeError: 'Info' object is not iterable

but if you use append method, result is OK. Because every time using extend method, it will always treat it as a list or any others collection type and iterate it and place it after the previous list.Specific object can not be iterated obviously.