Python_Built-in Types_list.extend

API文档:

array.extend(iterable)
Append items from iterable to the end of the array. If iterable is another array, it must have exactly the same type code; if not, TypeError will be raised. If iterable is not an array, it must be iterable and its elements must be the right type to be appended to the array.

翻译文档:

      参数:

             iterable:为一个数组或是string等

      描述:

            将iterable数组或是字符串追加到array中末尾。

            如果iterable为一个其他类型,则返回一个TypeError异常。如果iterable为字符串或是数组、元组等,则追加到array末尾

例子:

#! /usr/bin/env python
#coding=utf-8

list1=['a','b','c']
list2=['h','j']
print list1

list1.extend(list2)
print list1

list2=[1,'2']
list1.extend(list2)
print list1

list1.extend(1)
print list1

输出:

['a', 'b', 'c']
['a', 'b', 'c', 'h', 'j']
['a', 'b', 'c', 'h', 'j', 1, '2']
Traceback (most recent call last):
  File "F:\pyWorkSpace\notes\API\array_extend.py", line 15, in <module>
    list1.extend(1)
TypeError: 'int' object is not iterable


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值