Skip to content

导入Python模块的基本方式 #2

@Sogrey

Description

@Sogrey

导入Python模块的方式

import math #导入math包

print(math.sin(1.23))
from math import cos,tan #仅导入math包中的cos和tan
 #直接使用cos函数,不用再加`math.`了,
#如果还加`math.`就会抛出异常 `NameError: name 'math' is not defined`
print(cos(2.34)) 
print(tan(1.23))
from math import * #导入math包中全部函数
 #直接使用cos函数,不用再加`math.`了
#如果还加`math.`就会抛出异常 `NameError: name 'math' is not defined`
print(cos(2.34))
print(tanh(1.23))

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions