python中append、extend、和insert的区别

a_list = [x for x in range(1, 11)]
print(a_list)
a_list.append(sdadfewf)  # 将整个字符串放到列表的最后
print(a_list)
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ‘sdadfewf‘]

b_list = [x for x in range(1, 11)]
print(b_list)
b_list.extend(sdadfewf)  # 将字符串中的每个元素放到列表的最后
print(b_list)
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ‘s‘, ‘d‘, ‘a‘, ‘d‘, ‘f‘, ‘e‘, ‘w‘, ‘f‘]

c_list = [x for x in range(1, 11)]
print(c_list)
c_list.insert(3, sdadfewf)  # 将整个字符串插入到列表索引为3的位置
print(c_list)
# [1, 2, 3, ‘sdadfewf‘, 4, 5, 6, 7, 8, 9, 10]

 

python中append、extend、和insert的区别

上一篇:Android 9.0 Zygote 启动流程


下一篇:实现盒子水平移动