元组与字典练习题
来源:互联网 发布:php接口代码 编辑:程序博客网 时间:2024/05/12 11:52
元组的就到测试题
#1创建 score 元组,其中包含 10 个数值(68,87,92,100,76,88,54,89,76,61);tuple1=(68,87,92,100,76,88,54,89,76,61)
print(len(tuple1))#2输出 score 元组中第 3 个元素的数值;
print(len(tuple1))#3输出 score 元组中第 1~6 个元素的值;
print(tuple1[1:6])#4调用 count()函数,查询数值 76 在 score 元组中出现的次数;
print(tuple1.count(76))#5调用 index()函数,查询 score 元组中成绩是满分的学生学号;
print(tuple1.index(100))#6调用 len()函数获得 score 元组中元素的个数;
print(len(tuple1))#7调用 list()函数将 score 元组转换为 lstScore 列表;
tuple1=(68,87,92,100,76,88,54,89,76,61)list1=list(tuple1)print(list1)
#8调用 tuple()函数将 lstScore 列表转换为 tpScore 元组;
list1=(68,87,92,100,76,88,54,89,76,61)tpscore=tuple(list1)print(tpscore)
# 9创建 2 个元组 score1 和 score2,score1 中包含数值 2 个元素值:80,61,
# score2 中包含 3个元素值:71,95,82,合并这两个元组,并输出。
score1=(80,61)score2=(7,95,82)tuple3=score1+score2print(tuple3)
输入5个值,遍历输出列表的值
'''list=[]for i in range(0,5): list.insert(i,input(" 请输入:"))print(list)'''
动态给字典输入五个学生的姓名与手机号
'''print("="*40)mylist={}for i in range(0,5): a=input("请输入姓名") b=input("请输入手机号") mylist[a]=bprint(mylist)'''
字符串转元组
单词
阅读全文
0 0
- 元组与字典练习题
- py 元组, 列表与字典
- Python中的元组,列表与字典
- 元组与字典的一些方法
- Python元组与字典详解
- 列表元组字典
- 元组 数组 字典
- python 元组、字典
- Python元组&字典
- 数据字典与元数据
- Python 的元组、列表、字典区别与联系
- Python中的for循环(序列、元组与字典)
- Python基本数据结构之元组、集合与字典
- python复习笔记[5]——元组与字典
- Python:元组、列表、字典
- python字典,列表,元组
- 字符串、列表、字典、元组
- python 元组,列表,字典
- JAVA-dispose()方法
- C#——索引器使用总结
- 100. Same Tree
- Android开发中的网络判断
- leetcode— Integer to Roman
- 元组与字典练习题
- GDB十分钟教程,插图完整可显示
- 第十四周项目3
- leetcode 628. Maximum Product of Three Numbers
- ideal部署vue
- Apache Jena Fuseki的使用(windows 7)
- JavaScript中清空数组的三种方式
- 入门级python爬虫项目
- 比特币或区块链的创业思路【1】挖矿篇