|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
列表的学习结束啦。和一般的数组完全不一样,更加方便也更加有效。
本节课笔记
- list1 = [123]
- list2 = [234]
- list3 = [122,456]
- list1 > list2
- list1 > list3
- list4 = list1 + list2 + list3
- print('list1=',list1,'\n' 'list2=',list2,'\n''list3=',list3,'\n' 'list4=',list4)
- print(list1*3)
- list2 *= 3
- print(list2)
- print(dir(list)) #查看有几个和列表有关的dir
- print(list2.count(234)) #计算在234在列表中的个数
- print(list2.index(234)) #第一次出现的位置
- print(list2.index(234,1,3)) #在1‘3中第一次出现的位置
- print(list4)
- list4.reverse() #翻转列表
- print(list4)
- list4.sort() #列表按从小到大排序
- print(list4)
- list4.sort(reverse = True) #列表按从小到大排序
- print(list4)
复制代码
运行结果
- >>>
- ==================== RESTART: G:/学习/python/test 8--12.py ====================
- list1= [123]
- list2= [234]
- list3= [122, 456]
- list4= [123, 234, 122, 456]
- [123, 123, 123]
- [234, 234, 234]
- ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
- 3
- 0
- 1
- [123, 234, 122, 456]
- [456, 122, 234, 123]
- [122, 123, 234, 456]
- [456, 234, 123, 122]
- >>>
复制代码 |
评分
-
查看全部评分
|