牛客网专项练习30天Pytnon篇第02天

1.在Python3中,下列关于数学运算结果正确的是:(B)

a = 10
b = 3
print(a // b)
print(a % b)
print(a / b)

A.3,3,3.3333...

B.3,1,3.3333...

C.3.3333...,3.3333...,3

D.3.3333...,1,3.3333...

解析:

       在Python中,// 表示地板除(向下取整),% 表示取余, / 表示除(Python2向下取整返回3)


2.如下程序Python2会打印多少个数:(D)

k = 1000
while k > 1:
    print(k)
k = k/2

A.1000 

B.10

C.11

D.9

解析:

       按照题意每次循环K/2,直到K值小于等于1循环停止,Python2和Python3不同Python2除法会向下取整,第10次会返回整数1,导致循环停止不会打印。故只打印9次。


3.执行以下程序,输出结果为:D

a = 0 or 1 and True
print(a)

A.0   

B.1   

C.False   

D.True

解析:

       优先级从高往低依次为not、and、or。1 and True 结果为True, 0 or True为True。


4.python3中,执行 not 1 and 1的结果为:(B)

A.True 

B.False 

C.0

D.1

解析:

       在Python3中,not 表示逻辑非,and 表示逻辑与,逻辑非的运算优先级大于逻辑与的优先级,则 not 1 为False,则  not 1 and 1 结果为 False


5.在Python3中,执行print([2in [123])的结果为:(B)

A.True 

B.False 

C.[2] 

D.报错

解析:

       此题表示判断 [2] 是否在列表 [1, 2, 3]中,[2] 表示的是一个列表不是一个列表元素。因此 [2] 不在列表 [1, 2, 3]中,最后返回 False,如果是2 in [1, 2, 3]则返回True。 


牛客网专项练习30天Pytnon篇第02天_第1张图片

 

 

你可能感兴趣的:(牛客,python,开发语言,后端)