美文网首页Python 专题
小鱼儿学Python之导入库的n种方法

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

作者: 小鱼儿_yzh | 来源:发表于2022-06-15 18:59 被阅读0次

第一种: 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()

相关文章

网友评论

    本文标题:小鱼儿学Python之导入库的n种方法

    本文链接:https://www.haomeiwen.com/subject/zmvqvrtx.html