python程序框架
- 库
- 模块
- 语句
- 表达式
- 对象
- 表达式
- 语句
- 模块
模块
- 内置模块
__name__ =
内置模块
- id
- type
- dir
id() # 获取对象的内存地址
a = 11
print(id(a))
type(a) # 查看a的数据类型
dir() # 列出模块的属性和方法
print(dir(str))
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
package
包:由若干个模块组成的
package
- __init__.py
- module_a1.py
- module_a2.py
library
standlib
标准库
otherlib
第三方库
导入包
import moduleName # 导入包
from moduleName import XXX # 部分导入
import moduleName as alias # 起别名
from packageName.moduleName import projName[as]
from moduleName import * # 导入全部
语句
简单语句
input
复合语句
if elif else while for try raise yeild