关于学习Python的一点学习总结(4->成员资格->list->列表操作)

11.成员资格:检查特定的值是否包含在序列中,可使用运算符in.

 >>> presson='hello ,world!'
   >>> 'w' in presson
   True
   >>> 'j' in presson
   False
   >>> users=['mlh','foot','feet']
   >>> 'mlh' in users
    True

12.长度、最小值和最大值

  >>> num=[100,35,78,90]
   >>> len(num)
   4
   >>> min(num)
   35
   >>> max(num)
   100
   >>> min(2,3,4,5)
   2
   >>> max(6,7,8,9)
   9

13.函数list:

>>> list('hello')
  ['h', 'e', 'l', 'l', 'o']
                 

14.修改列表:给元素赋值

>>> num=[3,4,5]
   >>> num[1]=7
   >>> num
   [3, 7, 5]

15.列表删除元素

 >>> test=['first','second','third','fouth']
   >>> del test[1]
   >>> test
   ['first', 'third', 'fouth']
   

pop()删除元素(内部元素是按栈的方式存储的)

  >>> num=[1,2,3,4,5]
   >>> num.pop()
   5
   >>> num
   [1, 2, 3, 4]
   remove()移除列表中的元素:
   >>> num=[1,2,3,4,5]
   >>> num.remove(5)
   >>> num
   [1, 2, 3, 4]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值