话说为什么要用“入门级”举例来作为标题呢?那是因为,作为一个python初学者怎么能说解释好模块呢==,说实话模块我也是第一次接触,或许几章之后我就可以写篇“专业级”举例了,哈哈哈哈哈嗝。
以我现有的理解程度,模块或许就像MFC里的各种系统功能……==好吧,就当没说。
在之前的入门级turtle中,开始使用之前我们使用到了一句
import turtle
在使用模块的时候同样需要import(引入)云云……就像C语言里的头文件==
直接上小例子
>>> import time
>>> print(time.asctime())
Fri Oct 27 18:46:16 2017
再来一个
>>> import sys
>>> print(sys.stdin.readline())
What the f**k
What the f**k
>>>
看第二个例子,是不是觉得这是个没啥用的鸡肋?那么再看一下,如果我们将上一章的文章里的函数样例进行修改
原样例:
def checkage(_age):
if _age >= 18 and _age <= 60:
print("澳门首家线上*场上线啦!")
elif _age < 18:
print("You are too young to watch the video!")
else:
print("Are you OK?")
age = eval(input())
checkage(age)
修改后:
import sys
def checkage():
_age = eval(sys.stdin.readline())
if _age >= 18 and _age <= 60:
print("澳门首家线上*场上线啦!")
elif _age < 18:
print("You are too young to watch the video!")
else:
print("Are you OK?")
checkage()
这样就能看出作用了,说实话,写惯了input(),谁去写sys.stdin.readline()