Python编程四级 题库
共 6 道题
· 按题型筛选,点「查看答案」核对解析
2
单选题
适中
想要在Python中导入math模块中的sqrt(x)函数,下列程序段错误的是?( )
A
import math
math.sqrt(x)
B
from math import sqrt as t
t(x)
C
import math as m
m.sqrt(x)
D
import math
sqrt(x)
答案与解析
正确答案:D
3
单选题
适中
Python中可以通过import math 语句导入math函数库,下列选项中可以实现向下取整的是?( )
A
math.ceil()
B
math.sqrt()
C
math.round()
D
math.floor()
答案与解析
正确答案:D
floor()函数是math模块里的向下取整的函数。
4
单选题
适中
Python中,无需导入math库,可以直接使用的函数是?
A
ceil()
B
floor()
C
round()
D
sqrt()
答案与解析
正确答案:C
round()函数是Python内置函数,无需导入第三方库。
5
单选题
适中
Python中导入math模块中的sqrt(x)函数,下列程序段错误的是?
A
import math
math.sqrt(x)
B
from math import sqrt as sq
sq(x)
C
import math as m
m.sqrt(x)
D
import math
sqrt(x)
答案与解析
正确答案:D
第三方库的导入方法。
6
单选题
适中
在Python程序中,想要使用math库中的sqrt函数,下列哪种导入方式是错误的?( )
A
import math 然后使用math.sqrt(4)
B
from math import sqrt 然后使用sqrt(4)
C
import sqrt from math 然后使用sqrt(4)
D
from math import * 然后使用sqrt(4)
答案与解析
正确答案:C
分析Python中模块导入语句的语法结构。import语句用于整体导入模块,后续通过模块名访问函数;from...import语句从指定模块中导入特定函数或对象,可直接使用函数名调用;from...import * 将模块中所有名称导入当前命名空间,允许直接调用函数;import语句中关键字顺序必须为'import'在前,模块名在后,不能颠倒。若语法结构不符合Python语言规范,则该导入方式无效。