关于list.extend(iterable)
生活随笔
收集整理的這篇文章主要介紹了
关于list.extend(iterable)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
extend內的參數只要是iterable就可以,那么也可以添加定制的iterable,開整。
class A(object):def __init__(self):self.a = 0def __iter__(self):return selfdef next(self):self.a = self.a + 1if self.a > 10:self.a = 0raise StopIteration();return self.a>>> import collections >>> isinstance(a, collections.Iterable) True >>> import h >>> a = h.A() >>> for x in a: ... print x, ... 1 2 3 4 5 6 7 8 9 10 >>> l = list('sdfsd') >>> l ['s', 'd', 'f', 's', 'd'] >>> l.extend(a) >>> l ['s', 'd', 'f', 's', 'd', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
轉載于:https://www.cnblogs.com/iNeoWong/p/4719021.html
總結
以上是生活随笔為你收集整理的关于list.extend(iterable)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring AOP之异常转换
- 下一篇: 层模型--绝对定位、相对定位、固定定位