当前位置: 首页 > news >正文

品牌网站建设四川营销培训讲师

品牌网站建设四川,营销培训讲师,南京web前端培训班,灯具设计网站推荐list1 ["tom","cat","Lili"] print(list1[0].title())Tom#append()列表方法在列表末尾添加新元素 list1.append(233) print(list1) #可以先创建空列表,再进行追加append(..)以添加[tom, cat, Lili, 233]#insert()列表方法插入元素 l…
list1 = ["tom","cat","Lili"]
print(list1[0].title())
Tom
#append()列表方法在列表末尾添加新元素
list1.append(233)
print(list1)
#可以先创建空列表,再进行追加append(..)以添加
['tom', 'cat', 'Lili', 233]
#insert()列表方法插入元素
list1.insert(1,"kate")
print(list1)
['tom', 'kate', 'cat', 'Lili', 233]
#del...语句删除元素,注意这里是语句不是方法
del list1[2]
print(list1)
['tom', 'kate', 'Lili', 233]
#pop()列表方法删除(弹出)列表末尾的元素(对象)
poped_ele = list1.pop()
print(f"The poped element is {poped_ele}!")
print(f"The current list1 is {list1}")
#pop(n)可以从列表中部分弹出下标为n的元素
print(f"The 2th([1]) element 'kate' will be poped,the result is {list1.pop(1)} ")
The poped element is 233!
The current list1 is ['tom', 'kate', 'Lili']
The 2th([1]) element 'kate' will be poped,the result is kate 
print(f"The current list1 is {list1}")
The current list1 is ['tom', 'Lili']
#remove()列表方法根据值删除列表中的元素
list1.remove("tom")
print(f"The current list1 is {list1}")
The current list1 is ['Lili']
#sort()列表方法对列表进行默认永久排序(升)
list2 = ["d","a","c","b"]
list2.sort()
print(f"The sorted list2 is {list2}")
#reverse参数决定升降序,True则降序
The sorted list2 is ['a', 'b', 'c', 'd']
#sorted(listname)方法创建排序后的对象
list3= ["d","a","c","b"]
sorted_list3 = sorted(list3)
print(sorted_list3)
sorted_list3_reverse = sorted(list3,reverse=True)
print(sorted_list3_reverse)
['a', 'b', 'c', 'd']
['d', 'c', 'b', 'a']
#reverse(listname)方法反转列表顺序(不进行排序)
#len(list)确定列表长度
#4.操作列表
#list()将range()的结果转化为列表
numbers = list(range(1,6)) #[1,6)
print(numbers)
[1, 2, 3, 4, 5]
#min(listname),max(listname),sum(listname)对列表元素分别求最大最小与和
print(f"min:{min(numbers)} max:{max(numbers)} sum:{sum(numbers)}")
min:1 max:5 sum:15
#切片
list5 = list(range(1,6))
print(list5)
cut_list = list5[0:3]
print(cut_list)
[1, 2, 3, 4, 5]
[1, 2, 3]
#复制列表(浅拷贝)
list6 = list5[:]
print(list6)
print(id(list5) == id(list6))
[1, 2, 3, 4, 5]
False
#元组(元素不可变)
dimensions = (200,50)
print(f"({dimensions[0]},{dimensions[1]})")
for dimension in dimensions:print(dimension)
(200,50)
200
50
#in 和 not in判断元素是否在集合中
print(200 in dimensions)
print(300 not in dimensions)
True
True
#字典(键(字符串)值(任何对象)对集合)
dic = {'color' : 'yellow', "score" : 5,"a" : "3"}
dic["score"] = 3 #键不能变,值可以变,且可添加减少
print(dic)
print(dic["color"])
print(dic["score"])
print(dic["a"])
print("添加键值对:'name':'zhang san'")
dic['name'] = 'zhang san'
dic['name'].title()
print(f"添加后的字典是{dic}")
#也能进行遍历
print("遍历dic")
for key,value in dic.items():print(f"key:{key} value:{value}")
{'color': 'yellow', 'score': 3, 'a': '3'}
yellow
3
3
添加键值对:'name':'zhang san'
添加后的字典是{'color': 'yellow', 'score': 3, 'a': '3', 'name': 'zhang san'}
遍历dic
key:color value:yellow
key:score value:3
key:a value:3
key:name value:zhang san
#del() 语句可以删除键值对
del dic['score']
print()
#从字典中分离键值对,创建键值列表,items()方法可将字典生成列表(特殊列表,只可用for拷贝后使用)
#key()/values()方法可将字典的键/值生成列表(特殊列表,只可用for拷贝后使用)
keys = []
values = []
for key,value in dic.items():keys.append(key)values.append(value)pass
print(dic)
print(keys)
print(dic.keys())
print(dic.values())
print(values)
{'color': 'yellow', 'a': '3', 'name': 'zhang san'}
['color', 'a', 'name']
dict_keys(['color', 'a', 'name'])
dict_values(['yellow', '3', 'zhang san'])
['yellow', '3', 'zhang san']
#set()函数可以将传入的列表/元组去掉重复项,返回一个集合{...}
sets = set(list([1,1,1,2,3,4]))
print(sets)
{1, 2, 3, 4}
http://www.hkea.cn/news/686758/

相关文章:

  • 重庆网站建设要点襄阳seo优化排名
  • 哪个网站用织梦做的seo站长工具查询系统
  • 本地wordpress 上传搜索引擎优化简历
  • 个人创业做网站软文营销怎么写
  • wordpress相册点击弹出框金华seo全网营销
  • 郑州手机网站建设搜狗网站收录提交入口
  • 清风网站建设抖音推广方式有哪些
  • 工作室网站开发广东网站seo营销
  • 广州正佳广场攻略深圳债务优化公司
  • 如何自己免费建网站seo网站有哪些
  • 南昌网站建设案例如何制作自己的链接
  • wordpress大流量专业的网站优化公司
  • 做进口零食批发网站百度站长管理平台
  • 网站栏目建设存在的问题关键词简谱
  • 网站备案怎么那么麻烦google chrome 网络浏览器
  • 小米手机做网站服务器nba东西部最新排名
  • 做写字楼用哪个网站更好郑州seo代理外包
  • 做网站 淘宝营销策划思路
  • 网页设计要用到什么软件聊城seo优化
  • 用wordpress做网站百度推广管理
  • 一个空间可以放两个网站吗html模板网站
  • 做试用网站的原理网站推广优化平台
  • 软件工程培训机构学费亚马逊seo什么意思
  • 做恶搞网站软件有哪些苏州seo怎么做
  • 怎么做微信小说网站企业网络营销策划方案
  • 网站后台上传图片失败百度下载免费安装最新版
  • 镇江做网站需要多少钱企业网站模板设计
  • 西安seo优化系统网页seo
  • 如何用网站模板做网站广州网络营销推广
  • 承德手机网站建设seo推广排名