栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

《python编程,从入门到实践》第三章

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

《python编程,从入门到实践》第三章

#列表
website=['baidu','google','yahoo','bing']
print(website)
print(website[0])#访问
print(website[0].title())#索引从0开始
print(website[-1])#倒数

message="Try "+website[1].title()+"!"
print(message)

website[2]='2345'#更改元素
print(website)

website.append("yahoo") #append在末尾添加新元素
print(website)

website.insert(0,'360')#insert在指定位置插入
print(website)

del website[0]#delete删除指定为位置
print(website)

poped_1=website.pop()#pop弹出最后一个元素,类似”栈“
print(poped_1)
print(website)

poped_2=website.pop(1)#弹出指定位置元素
print(poped_2)
print(website)

website.remove("2345")#指定值删除   只删除第一个值,如有重复,需用循环
print(website)

removetip='bing'
website.remove(removetip)#指定变量
print(website)

#3.3组织列表
cars=['bmw','audi','toyota','volvo']
cars.sort()#排序(永久性)
print(cars)
cars.sort(reverse=True)#相反顺序
print(cars)

print(sorted(cars))#临时排序

cars.reverse()#顺序颠倒(永久性)
print(cars)

print(len(cars))#长度

#3.4注意索引错误
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/275373.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号