标准模块脚本
#coding= utf-8
#当有中文字符时必须在开头定义编码,需要符合coding[:=]\s*([-\w.]+)正则
#比如这种卖萌的书写方法_*_ coding: utf-8 _*_
# "#"符号表示注释当前行
"""
三个双引号开头三个双引号结束,表示注释多行
"""
"这是一个标准模块脚本的写作范式,此处为该脚本文档."
引入模块标准库模块
import time
print time.time()#输出时间戳,time是Python的标准模块库
我们还可以自己定义模块,例如:
#定义一个模块stand,文件名stand.py
#代码为:
#coding= utf-8
new_str = "这是一个全局变量"
def hello():
return "Hello world"
if __name__ = "_name_"
print hello()`
在1211.朋友中,引用这个模块stand:
import stand #只使用文件名引入,其实引入的是stand.pyc文件(由stand.py第一次执行时编译出来)
print stand.__doc__ #输出解释文档
print stand.new_str #输出stand中的全局变量
print stand.hello() #拿出函数,输出结果