import flask # 可以使用flask中所有的属性和方法# 使用flask中的Flask,用如下方式flask.Flask()from sys import version_info # 使用sys中的version_infofrom flask import Flaskapp = Flask(__name__)@app.route('/')
def demo():return 'hello world'if __name__ == "__main__":app.run()
# import 模块名1, 模块名2(多个模块同时导入)import math # 导入模块的所有功能# 调用时使用 模块名.功能
print(math.sqrt(9))from math import sqrt # 导入指定的功能名# 使用时不需要写模块名
print(sqrt(9))# 也可以这样调用
from math import *# 使用时也不需要写模块名
print(sqrt(9))
"""
as定义别名1 模块定义别名 语法
import 模块名 as 别名2 功能定义别名
from 模块名 import 功能 as 别名"""# 1 模块定义
import time as tt # 定义成别名后,只能使用别名tt,不能使用原模块名timett.sleep(2)
print('hello')# 2 功能定义,不需要写模块名
from time import sleep as ss # 定义成ss后,下面调用只能使用ssss(2) # 这里只能使用ss,不能使用sleep
print('world')
简单描述下__all__的作用
__all__ = ['testA']
# 当使用from 模块名 import * 导入时,只能导入testAdef testA():print('testA')def testB():print('testB')