码迷,mamicode.com
首页 > 编程语言 > 详细

python3实践

时间:2017-02-03 22:49:49      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:image   shu   style   需求   .com   log   name   position   并且   

 需求

name = [‘wangxiaohua‘,‘wangdashu‘,6,9,9,80,‘haha‘,‘alex‘,34,34,‘wq‘,34,9,‘dfd‘,34,9,‘weew‘]
找出name列表中有多少个9并且全部将9修改成9999
找出所有的34并且全部删除

 思维导图

技术分享

 代码

name = [wangxiaohua,wangdashu,6,9,9,80,haha,alex,34,34,wq,34,9,dfd,34,9,weew]

#将name列表中的所有9修改成9999
for i in  range(name.count(9)):
    position_of_ele = name.index(9)
    name[position_of_ele] = 9999
    print(name)
    
#删除name列表中的所有34元素
for i in  range(name.count(34)):
    position_of_ele = name.index(34)
    name.remove(34)
    print(name)


#打印结果
‘‘‘
将全部9修改为9999
[‘wangxiaohua‘, ‘wangdashu‘, 6, 9999, 9, 80, ‘haha‘, ‘alex‘, 34, 34, ‘wq‘, 34, 9, ‘dfd‘, 34, 9, ‘weew‘]
[‘wangxiaohua‘, ‘wangdashu‘, 6, 9999, 9999, 80, ‘haha‘, ‘alex‘, 34, 34, ‘wq‘, 34, 9, ‘dfd‘, 34, 9, ‘weew‘]
[‘wangxiaohua‘, ‘wangdashu‘, 6, 9999, 9999, 80, ‘haha‘, ‘alex‘, 34, 34, ‘wq‘, 34, 9999, ‘dfd‘, 34, 9, ‘weew‘]
[‘wangxiaohua‘, ‘wangdashu‘, 6, 9999, 9999, 80, ‘haha‘, ‘alex‘, 34, 34, ‘wq‘, 34, 9999, ‘dfd‘, 34, 9999, ‘weew‘]


将34元素全部删除
[‘wangxiaohua‘, ‘wangdashu‘, 6, 9999, 9999, 80, ‘haha‘, ‘alex‘, 34, ‘wq‘, 34, 9999, ‘dfd‘, 34, 9999, ‘weew‘]
[‘wangxiaohua‘, ‘wangdashu‘, 6, 9999, 9999, 80, ‘haha‘, ‘alex‘, ‘wq‘, 34, 9999, ‘dfd‘, 34, 9999, ‘weew‘]
[‘wangxiaohua‘, ‘wangdashu‘, 6, 9999, 9999, 80, ‘haha‘, ‘alex‘, ‘wq‘, 9999, ‘dfd‘, 34, 9999, ‘weew‘]
[‘wangxiaohua‘, ‘wangdashu‘, 6, 9999, 9999, 80, ‘haha‘, ‘alex‘, ‘wq‘, 9999, ‘dfd‘, 9999, ‘weew‘]
‘‘‘

 

python3实践

标签:image   shu   style   需求   .com   log   name   position   并且   

原文地址:http://www.cnblogs.com/little-turtle/p/6363487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!