学习笔记(6):零基础掌握 Python 入门到实战-列表与元组到底该用哪个?(二)

立即学习:https://edu.csdn.net/course/play/26676/338778?utm_source=blogtoedu

lst = [1,2,3,4]

lst[2] = 300

lst now is [1,2,300,4]

element in list can be changed

lst.qppend("python)

now lst is [1,2,300,4,'python']

it doesn't create a new list

lst.insert(0,10)

now lst is [10,1,2,300,.....]

lst2 = ['a','b']

lst.extend(lst2)

now a b are at the end of lst

also if extend a word eg. book

it will become 'b', 'o','o','k'

 lst.pop() means delete the last element and show it in the outcome

lst.remove('b')

romeve one b in the list 

lst.clear() clear the whole list

but!!!! is use eg, a = [1,2,3]

                           a =[ ]

this bulids a new a, different with the method clear above

use sort to sort it from small to large

is want the reverse, use sort(severse = Ture)

or it can be lst[::-1]

s= "python"

lst = list(s)

lst now is ['p','y','t'.......]

then

"".join(lst) gives 'python'

can not use str(lst)

or it will be "['p','y','t'......]"

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值