Skip to content

为导入Python模块指定别名 #3

@Sogrey

Description

@Sogrey

给模块指定别名 as

import math as m
print(m.sin(20))
#print(math.sin(20)) # NameError: name 'math' is not defined
from math import cos as c
print(c(3)) #这里的`c`指代的就是`math.cos`
print(cos(12)) #虽然指定了别名,但原名依然可用

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions