#LS1001. Python基础客观题
Python基础客观题
一、单选题
- Python表达式 [1, 2, 3] + [4, 5] 的结果是( )。 {{ select(1) }}
- [1, 2, 3, 4, 5]
- [5, 7, 8]
- 报错
- []
- Python语句 print(type({})) 执行后的输出是( )。 {{ select(2) }}
- <class 'set'>
- <class 'dict'>
- <class 'list'>
- <class 'tuple'>
- 执行Python代码 x = 10; y = x; x = 20; print(y),下述说法正确的是 ( ) {{ select(3) }}
- 输出 20
- 输出 10
- 输出 None
- 报错,变量未定义
- 下面Python代码执行后的输出是 ( )
a = "Hello"
print(a[1:4])
{{ select(4) }}
- Hel
- ell
- ello
- hello
- 下面Python代码执行后的输出是( )。
d = {'a': 1, 'b': 2}
print(d.get('c', 0))
{{ select(5) }}
- None
- 0
- KeyError
- 'c'
- 下面Python代码执行后,有关描述正确的是( )。
nums = [1, 2, 3, 4, 5]
result = [x for x in nums if x % 2 == 0]
print(result)
{{ select(6) }}
- 输出 [1, 3, 5]
- 输出 [2, 4]
- 输出 [1, 2, 3, 4, 5]
- 代码报错
- 下面Python代码第2行,总共被执行次数是( )。
count = 0
for i in range(1, 6):
count += 1
print(count)
{{ select(7) }}
- 4
- 5
- 6
- 0
- 下面Python代码执行后的输出是( )。
def func(a, b=[]):
b.append(a)
return b
print(func(1))
print(func(2))
{{ select(8) }}
- [1] 和 [2]
- [1] 和 [1, 2]
- [1] 和 [2, 1]
- 报错
- 下面Python代码执行后的输出是( )。
s = "Python"
print(s[::-1])
{{ select(9) }}
- Python
- nohtyP
- Pytho
- n
- 下面Python代码用于计算1到100的和。在横线处应填入代码是( )。
total = 0
for i in range(1, 101):
_________________
print(total)
{{ select(10) }}
- total = i
- total += i
- total = total * i
- i += total
- 下面关于Python列表的操作不正确的是( )。 {{ select(11) }}
- lst.append(1)
- lst.insert(0, 1)
- lst.pop()
- lst.add(1)
- Python语言中下面可以完成数据输入的函数是( )。 {{ select(12) }}
- print()
- input()
- scanf()
- cin >>
- 在Python中,要将一个字符串转换为整数,需要执行下面哪个操作?( ) {{ select(13) }}
- str()
- float()
- int()
- bool()
- Python中用于表示“空”或“无”的关键字是?( ) {{ select(14) }}
- null
- undefined
- None
- void
- 下列哪个不是Python的保留关键字?( ) {{ select(15) }}
- if
- else
- switch
- while
二、判断题(每题 2 分,共 20 分)
- 在Python代码中,表达式 3 ** 2 的结果是9。( ) {{ select(16) }}
- 正确
- 错误
- Python语句 print("Hello", end="") 执行后不会自动换行。 ( ) {{ select(17) }}
- 正确
- 错误
- Python列表是可变对象,而元组是不可变对象。( ) {{ select(18) }}
- 正确
- 错误
- Python表达式 "10" + 2 执行时将报错,因为字符串和整数不能直接相加。( ) {{ select(19) }}
- 正确
- 错误
- 在Python中,字典的键可以是列表。( ) {{ select(20) }}
- 正确
- 错误
- 在Python中,break语句只能用于循环结构,不能用于if语句。( ) {{ select(21) }}
- 正确
- 错误
- Python中 == 比较的是值,而 is 比较的是内存地址。( ) {{ select(22) }}
- 正确
- 错误
- 在Python的程序中,_name 是一个合法的变量名。( ) {{ select(23) }}
- 正确
- 错误
- Python中的集合(set)元素是无序且不重复的。( ) {{ select(24) }}
- 正确
- 错误
- 任何一个while循环都可以转化为等价的for循环( )。 {{ select(25) }}
- 正确
- 错误