首页 > 编程语言 > 详细

Python day02心得

时间:2017-11-07 14:14:34      阅读:316      评论:0      收藏:0      [点我收藏+]

运算符优先级

技术分享

元组、字典、列表

元组:只能创建和查,不能修改(方法:count 、 index)

 列表: 增、删、改、查、索引、切片(方法:append、insert、pop、del、index、len)

 列表扩展:

>>> names
[‘Alex‘, ‘Tenglan‘, ‘Rain‘, ‘Tom‘, ‘Amy‘]
>>> b = [1,2,3]
>>> names.extend(b)
>>> names
[‘Alex‘, ‘Tenglan‘, ‘Rain‘, ‘Tom‘, ‘Amy‘, 1, 2, 3]

字典(无序):增、删、改、查、索引(方法:get、clear、popitem)

#setdefault(字典中有就不变,没有就添加)
>>> info.setdefault("stu1106","Alex")   
‘Alex‘
>>> info
{‘stu1102‘: ‘LongZe Luola‘, ‘stu1103‘: ‘XiaoZe‘, ‘stu1106‘: ‘Alex‘}

#update 
>>> info
{‘stu1102‘: ‘LongZe Luola‘, ‘stu1103‘: ‘XiaoZe‘, ‘stu1106‘: ‘Alex‘}
>>> b = {1:2,3:4, "stu1102":"bala"}
>>> info.update(b)
>>> info
{‘stu1102‘: ‘bala‘, 1: 2, 3: 4, ‘stu1103‘: ‘XiaoZe‘, ‘stu1106‘: ‘Alex‘}

#通过一个列表生成默认dict,有个没办法解释的坑,少用吧这个
>>> dict.fromkeys([1,2,3],‘testd‘)
{1: ‘testd‘, 2: ‘testd‘, 3: ‘testd‘}

补充

enumerate用法:

for index,item in enumerate(proc_name):

  index ----> 下标

  item ------> 元素

 

 

Python day02心得

原文:http://www.cnblogs.com/sshcy/p/7780502.html

(0)
(0)
   
举报
评论 一句话评论(0
分享档案
最新文章
教程昨日排行
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!