您当前的位置:首页 >> 人工智能
人工智能

python数据类型-年表(list)

发布时间:2025-09-17

问道inhobbies = ['play', 'eat', 'sleep', 'study']print('sleep' in hobbies) # Truemsg = 'hello world sz'print('sz' in msg) # True插入成分insert()hobbies = ['play', 'eat', 'sleep', 'study', 'eat', 'eat']hobbies.insert(1, 'walk')print(hobbies)hobbies.insert(1, ['walk1', 'walk2', 'walk3'])print(hobbies)"""['play', 'walk', 'eat', 'sleep', 'study', 'eat', 'eat']['play', ['walk1', 'walk2', 'walk3'], 'walk', 'eat', 'sleep', 'study', 'eat', 'eat']"""统计乘积count()hobbies = ['play', 'eat', 'sleep', 'study', 'eat', 'eat']print(hobbies.count('eat')) # 3一览表分割extend()

list1.extend(list2) 将list2之中的成分从list1的结尾添加上list1之中

hobbies = ['play', 'eat', 'sleep', 'study', 'eat', 'eat']hobbies.extend(['walk1', 'walk2', 'walk3'])print(hobbies) # ['play', 'eat', 'sleep', 'study', 'eat', 'eat', 'walk1', 'walk2', 'walk3']获取某个成分的书目index()如果一览表之中有也就是问道成分,则留在也就是问道成分第一次出现的书目如果一览表之中无法也就是问道成分,无法就报错hobbies = ['play', 'eat', 'sleep', 'study', 'eat', 'eat']print(hobbies.index('eat')) # 1print(hobbies.index('girl')) # 报错清空成分clear()hobbies = ['play', 'eat', 'sleep', 'study', 'eat', 'eat']hobbies.clear()print(hobbies) # []一览表拷贝copy()

一览表拷贝属于浅拷贝, 更改一览表之中的成分就会相互影响,切记,这里不展开问道,后面就会详细问道

hobbies = ['play', 'eat', 'sleep', 'study', 'eat', 'eat']l = hobbies.copy() # ['play', 'eat', 'sleep', 'study', 'eat', 'eat']print(l)一览表相反reverse()l = [1, 2, 3, 4, 5]l.reverse()print(l) # [5, 4, 3, 2, 1]一览表先后依序sort()l = [100, 9, -2, 11, 32]l.sort()print(l) # [-2, 9, 11, 32, 100]l = [1, 4, 5, 2, 6]l.sort(reverse=True)print(l) # [6, 5, 4, 2, 1]。

南京妇科医院哪个专业
银川看白癜风哪家专科医院好
重庆白癜风专科医院哪家好
北京哪家医院专业做人流
重庆看白癜风的医院哪家好

上一篇: 某百万主播攻防战砍拼多多,六万人在线帮砍两小时竟都没成功

下一篇: 卡瓦哈尔:萨拉赫很难复仇皇马 姆巴佩不愿离舒适区

友情链接