Python中的append()方法
Python中的append()方法append()append()append()方法表示在原来的列表末尾追加新的对象。如我们在一个数组的后面添加一个元素x = [1, 2, 3, 4, 5, 6, 7, 8, 9]x1 = (2)x2 = []def fun(i):i.append(x1)return iy1 = fun(x)y2 = fun(x2)print('在数组x:后加入元素2:',
·
Python中的append()方法
append()
append()方法表示在原来的列表末尾追加新的对象。
如我们在一个数组的后面添加一个元素
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
x1 = (2)
x2 = []
def fun(i):
i.append(x1)
return i
y1 = fun(x)
y2 = fun(x2)
print('在数组x:后加入元素2:', y1)
print('在数组x2中添加元素2:', y2)
-----------------------------------------------
输出结果:
在数组x后加入元素2: [1, 2, 3, 4, 5, 6, 7, 8, 9, 2]
在数组x2中添加元素2: [2]
更多推荐
已为社区贡献1条内容
所有评论(0)