青少年软件编程(python二级)等级考试试卷-客观题(2023年3月)
{123:'a','a':123}不是一个合法的字典
数字、字符串、列表和元组都可以作为字典的键
{(12,34,'a'):'a','a':5678}是一个合法的字典
字典中的内容一经创建就不能再修改
(age=18)
[age=18]
age=18
{'age': 18}
(191,98,1,0)
"1919,810"
[19,19,8,10]
{19,'19',8,10}
4
5
6
7
-2
-3
2
5
print(min(list9))可以输出列表的最小值,输出结果为0
print(max(list9))可以输出列表的最大值,输出结果为514
print(list9.index(191))可以输出数值191第一个匹配项的索引位置,输出结果为3
list9.remove()可以移除列表中的最后一个元素
'0123456'是一个长度为6的字符串
在Python中,可以用乘号'*'把两个字符串连接起来
'What's this?'是一个合法的字符串
'*'是一个合法的字符串
while语句通常用于重复执行某一段程序
break语句可以跳出for和while的循环体
在Python中可以使用do..while循环
if语句通常用于执行条件判断
1
2
3
4
-1
1
0
2023
ls.pop(-1)
del ls[-1]
ls.remove(ls[-1])
ls.remove(-1)
Happy
Good
Luck
o
2
3
6
7
ls[-5:-2:-2]
ls[-5:-2:2]
ls[4:-3:1]
ls[4:-2:2]
['Failure','is','the','mother','of','success']
['Failure','is','the','mother','of','success','of','is']
['Failure', 'is', 'the', 'mother', 'of', 'success', 'is', 'of']
['Failure', 'is', 'the', 'mother', 'of', 'success', 'is', 'the', 'of']
tp=('a',)
tp=('',[],20) 备注:这里是单引号
tp=(25)
tp=1,2,3
元组的元素只能是不可变数据类型,例如:整型、浮点型、字符串、元组
元组一旦创建不可以修改
列表可以切片,元组不能切片
元组之间的元素不能用逗号进行分隔
'字符串' '运算'
''.join(['字符串','运算'])
‘字符串运算’*1
'字符串’-’运算'
‘Python, need, You’
'Python,You,need'
‘need,You,Python’
‘need,Python,You’
GhatGPT 百度 Google
聊天机器人 搜索引擎 浏览器
['GhatGPT','百度','Google' ]
[('聊天机器人','GhatGPT'),('搜索引擎','百度'),('浏览器','Google' )]
a = 0
while a<10:
if a%2 == 0:
a = a 1
continue
print(a,end=' ')
a = a 1
for a in range(0,11):
if a%2 != 1:
continue
print(a,end=' ')
for a in range(0,11):
if a%2 == 0:
continue
print(a,end=' ')
a = 0
while a<10:
if a%2 == 1:
break
a = a 1
print(a)
36
45
50
55
print(tup2[1:-2])可以截取元组的一部分,输出的结果为(5,14)
print(tup2[2:])可以截取元组的一部分,输出的结果为(5,14,191,9810)
print(tup2[2:3])可以截取元组的一部分,输出的结果为(14,)
print(tup2[3])可以访问元组的第四个元素,输出的结果为191
发表评论 取消回复