Python 专题

小鱼儿学Python之导入库的n种方法

2022-06-15  本文已影响0人  小鱼儿_yzh

第一种: import 库名

这种导入方法,在使用时要带类名,如turtle.fd()

import turtle
turtle.fd(100)
turtle.done()

第二种: import 库名 as 变量名

这种导入方法,在使用时用 变量名 代替 类名,如 t.fd()

import turtle as t
t.fd(100)
t.done()

第三种: from 库名 import *

这种导入方法,在使用时不需要带类名,可以使用该库中所有的方法和函数。

from turtle import *
fd(100)
done()

第四种: from 库名 import 方法列表

这种导入方法,在使用时不需要带类名,只能使用“方法列表”中列出的方法和函数。

from turtle import fd,done
fd(100)
done()
上一篇下一篇

猜你喜欢

热点阅读