美文网首页
进阶篇6-函数周末习题

进阶篇6-函数周末习题

作者: 梦归游子意 | 来源:发表于2017-02-13 16:23 被阅读0次
    • python append()和extend()用法
    append()用法示例:
    
    >>> mylist = [1,2,0,'abc']
    
    >>> mylist
    
    [1, 2, 0, 'abc']
    
    >>> mylist.append(4)
    
    >>> mylist
    
    [1, 2, 0, 'abc', 4]
    
    >>> mylist.append('haha')
    
    >>> mylist
    
    [1, 2, 0, 'abc', 4, 'haha']
    
    extend()用法示例:
    
    >>> mylist
    
    [1, 2, 0, 'abc', 4, 'haha']
    
    >>> mylist.extend(['lulu'])
    
    >>> mylist
    
    [1, 2, 0, 'abc', 4, 'haha', 'lulu']
    
    >>> mylist.extend([aaa,'lalalala'])
    
    Traceback (most recent call last):
    
      File "<stdin>", line 1, in <module>
    
    NameError: name 'aaa' is not defined
    
    >>> mylist.extend(['123123','lalalala'])
    
    >>> mylist
    
    [1, 2, 0, 'abc', 4, 'haha', 'lulu', '123123', 'lalalala']
    
    >>> mylist.extend([111111,222])
    
    >>> mylist
    
    [1, 2, 0, 'abc', 4, 'haha', 'lulu', '123123', 'lalalala', 111111, 222]
    
    >>>
    
    

    相关文章

      网友评论

          本文标题:进阶篇6-函数周末习题

          本文链接:https://www.haomeiwen.com/subject/yectwttx.html