py--list

Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> lsit =[]
>>> list =[]
>>> type(list)
<class 'list'>
>>> list=[1,2,3,4]
>>> list
[1, 2, 3, 4]
>>> list=['str',1,2]
>>> list
['str', 1, 2]
>>> list=[1,'str',['list',123]]
>>> list
[1, 'str', ['list', 123]]
>>> len(list}
SyntaxError: invalid syntax
>>> len(list)
3
>>> list[2][1]
123
>>> #可以放任何类型
>>> list=list([1,2,3])
Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    list=list([1,2,3])
TypeError: 'list' object is not callable
>>> #操作
>>> a=[1,2,3,4]
>>> b=[2,3,4,5]
>>> a+b
[1, 2, 3, 4, 2, 3, 4, 5]
>>> type(a+b)
<class 'list'>
>>> a*2
[1, 2, 3, 4, 1, 2, 3, 4]
>>> a
[1, 2, 3, 4]
>>> del a[0]
>>> a
[2, 3, 4]
>>> 
>>> a[0:]
[2, 3, 4]
>>> a[0]=123
>>> a
[123, 3, 4]
>>> 3 in a
True
>>> 7 not in a
True
>>> a=[1,2,3,4,5]
>>> a[1:]
[2, 3, 4, 5]
>>> a
[1, 2, 3, 4, 5]
>>> del a[3:]
>>> a
[1, 2, 3]
>>> str='hello python'
>>> 'hello' in str
True
>>> list=['apple','orange','apple','orange']
>>> list.count('apple')
2
>>> list.index('apple')
0
>>> list.append('pear')
>>> list
['apple', 'orange', 'apple', 'orange', 'pear']
>>> list.append([12,34])
>>> list
['apple', 'orange', 'apple', 'orange', 'pear', [12, 34]]
>>> list.insert(1,'hh')
>>> list
['apple', 'hh', 'orange', 'apple', 'orange', 'pear', [12, 34]]
>>> list.remove ('hh')
>>> list
['apple', 'orange', 'apple', 'orange', 'pear', [12, 34]]
>>> list.remove('apple')
>>> list
['orange', 'apple', 'orange', 'pear', [12, 34]]
>>> list.pop()
[12, 34]
>>> list
['orange', 'apple', 'orange', 'pear']
>>> list=[1,2,5,4,3,2]
>>> list.sort()
>>> list
[1, 2, 2, 3, 4, 5]
>>> list=[3,2,11,1,5]
>>> list1= sorted(list)
>>> list
[3, 2, 11, 1, 5]
>>> list1
[1, 2, 3, 5, 11]
>>> list=['liu', 'yong']
>>> list.reverse()
>>> list
['yong', 'liu']
>>> 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值