在Python中调用模块的函数可以通过以下几种方式:
1. 使用`import`语句导入整个模块,然后通过模块名调用函数:
import math
result = math.sqrt(16)
print(result) 输出:4.0
2. 使用`from...import`语句导入特定的函数,然后直接调用该函数:
from math import sqrt
result = sqrt(16)
print(result) 输出:4.0
3. 使用`from...import...as`语句给模块起别名,然后通过别名调用函数:
from math import sqrt as square_root
result = square_root(16)
print(result) 输出:4.0
4. 使用`import *`通配符导入模块中的所有内容,然后直接调用函数:
from math import *
result = sqrt(16)
print(result) 输出:4.0
请根据你的需求选择合适的调用方式