python3元组_python3 列表、元组操作

alist = [1,2,3,4,5,6,7,8,9]

alist

[1, 2, 3, 4, 5, 6, 7, 8, 9]

alist. #两次TAB键

alist.append( #添加

alist.count(9) #统计单个字符出现的次数

alist.insert( #插入在指定位置插入参数

>>> alist.insert(3,4)

>>> alist

[1, 2, 3, 4]

alist.reverse() #倒序打印

alist.clear(

alist.extend('new') #把new当成三个字符,进行添加

>>> alist.extend('new')

>>> alist

[1, 2, 3, 4, 5, 6, 7, 8, 9, 'n', 'e', 'w']

>>> alist.extend(['hello','world'])

>>> alist

[1, 2, 3, 4, 5, 6, 7, 8, 9, 'n', 'e', 'w', 'hello', 'world']

alist.pop( #删除,并弹出

alist.sort() #升序排序,改变列表本身

>>> alist = [3,5,2,6,2]

>>> alist.sort()

>>> alist

[2, 2, 3, 5, 6]

alist.copy(

alist.index(6) #返回参数的下标,一个参数出现多次返回第一个参数的下标

>>> alist.index(6)

5

alist.remove(

shuffle #打乱列表顺序

>>> from random import shuffle

>>> alist

[97, 97, 97, 94, 79, 70, 57, 16, 11, 9]

>>> shuffle(alist)

>>> alist

[79, 16, 97, 94, 97, 11, 97, 70, 9, 57]

join:

>>> str_list = ['h','e','l','l','o']

>>> str_list

['h', 'e', 'l', 'l', 'o']

>>> ''.join(str_list) #将列表转换成字符串,以空为链接符

'hello'

>>> '.'.join(str_list) #以.为链接符,转换列表为字符串

'h.e.l.l.o'

元组:

atuple = (1, [], 3)

atuple = (1, [], 3)

atuple

(1, [], 3)

atuple[1]

[]>>> atuple[1].append(2)

atuple

(1, [2], 3)

atuple[1].append(3)

atuple

(1, [2, 3], 3)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值