首页 / PYTHON / python-组合数据类
python-组合数据类
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python-组合数据类,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2464字,纯文字阅读大概需要4分钟。
内容图文
列表:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
s=list(‘kkkkk‘) s.insert(3,2) s.pop(3) s[6]=1 print(s) print(‘第一个1的位置是:‘,s.index(‘1‘)) x=0 y=0 for i in range(len(s)): if s[i]==‘3‘: x=x+1 if x==1: y=i print(‘三分个数为:‘,x,‘ ‘,‘第一个三分位置是:‘,y) print(‘二分个数为:‘,s.count(‘2‘))
字典:建立学生学号成绩字典,做增删改查遍历操作。
>>> dic=dict(zip([1,2,3],[‘98‘,‘100‘,‘88‘])) >>> dic {1: ‘98‘, 2: ‘100‘, 3: ‘88‘} >>> dic2={4:‘95‘} >>> dic.update(dic2) >>> dic {1: ‘98‘, 2: ‘100‘, 3: ‘88‘, 4: ‘95‘} >>> dic.pop(2) ‘100‘ >>> dic {1: ‘98‘, 3: ‘88‘, 4: ‘95‘}
>>> dic {1: ‘120‘, 3: ‘88‘, 4: ‘95‘} >>> del dic[3] >>> dic {1: ‘120‘, 4: ‘95‘} >>> dic[1]=‘120‘ >>> dic {1: ‘120‘, 3: ‘88‘, 4: ‘95‘} >>> dic {1: ‘98‘, 3: ‘88‘, 4: ‘95‘} >>> dic.get(4) ‘95‘ >>> dic.get(5,‘没有‘) ‘没有‘
>>> dic[4] ‘95‘ >>> dic.keys() dict_keys([1, 3, 4]) >>> dic.values() dict_values([‘98‘, ‘88‘, ‘95‘]) >>> dic.items() dict_items([(1, ‘98‘), (3, ‘88‘), (4, ‘95‘)]) dict
列表,元组,字典,集合的遍历。
s=list(‘456132798‘) t=set(‘4561327489‘) c={‘小明‘:‘1‘,‘小红‘:‘3‘,‘小华‘:‘2‘} x=(1, 2, 3, 4, 5 ) print(‘列表的遍历为:‘,end=‘‘) for i in s: print(i,end=‘‘) print() print(‘元祖的遍历为:‘,end=‘‘) for i in x: print(i,end=‘‘) print() print(‘字典key的遍历为:‘,end=‘‘) for i in c: print(i,end=‘‘) print() print(‘字典value的遍历为:‘,end=‘‘) for i in c.values(): print(i,end=‘‘) print() print(‘数组的遍历为:‘,end=‘‘) for i in x: print(i,end=‘‘)
‘‘‘ 下载一首英文的歌词或文章,统计单词出现的次数,将所有,.?!替换为空格,将所有大写转换为小写。 ‘‘‘ sr=‘‘‘You‘re ?insecure Don‘t know what for You‘re turning heads through the door Don‘t need make-up to cover up Being the way that you are is enough Everyone else in the room can see it Everyone else but you Baby you light up my world like nobody else The way that you flip your hair gets me overwhelmed But when you smile at the ground it ain‘t hard to tell You don‘t know Oh oh You don‘t know you‘re beautiful If only you saw what I can see You‘ll understand why I want you so desperately Right now I‘m looking at you and I can‘t believe You don‘t know Oh !oh You don‘t know you‘re beautiful Oh oh That‘s what makes you beautiful So c-come on You got it wrong To prove I‘m ,right ‘‘‘ print(sr.count(‘you‘)) for i in sr: sr=sr.replace(‘,‘,‘/t ‘) sr=sr.replace(‘!‘,‘/t ‘) sr=sr.replace(‘?‘,‘/t ‘) print(sr) for i in sr: sr=sr.upper() print(sr)
原文:http://www.cnblogs.com/ljx123/p/7567785.html
内容总结
以上是互联网集市为您收集整理的python-组合数据类全部内容,希望文章能够帮你解决python-组合数据类所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。