somepeople

python学习第二天-列表

extend()

扩展列表,没有返回值

lis_1 = [1,2,3,4,5,'a']
lis_2 = ['b','c','d']
lis_1.extend(lis_2)
print(lis_1)
#[1, 2, 3, 4, 5, 'a', 'b', 'c', 'd']

排序

列表元素不同数据类型不支持排序

lis_1 = [1,2,3,4,5,'a']
lis_3 = ['1','2','3']
lis_2 = ['b','c','d']
lis_1.sort()
lis_3.sort()
lis_2.sort()
print(lis_1,lis_2,lis_3)

Traceback (most recent call last):
File "E:/pythondir/Day01/day01.py", line 4, in <module>
lis_1.sort()
TypeError: '<' not supported between instances of 'str' and 'int'

posted on 2020-07-05 21:14  Hello_Thanos  阅读(117)  评论(0编辑  收藏  举报

导航