(1)、模块
标准模块、第三方模块
初识模块:sys \ os
一般标准库存放路径 C:\Users\Administrator\AppData\Local\Programs\python\Python35\Lib
第三方引用安装库存放路径:C:\Users\Administrator\AppData\Local\Programs\Python\Python35\Lib\site-packages
模块引用范例:
import sys
import os
print(sys.path)#打印环境变量路径
print(sys.argv)#打印当前脚本的相对路径
os.system("dir")#打印输出,但不保存结果,只返回执行成功与否值
_memory = os.popen("dir")
print(_memory)#打印 输出的内存地址
print(_memory.read())#打印目录列表
os.mkdir("new_dir")#创建一个目录
os.rmdir("new_dir")#删除一个目录
pyc c(compile)编译,(预编译之后的字节码文件)自定义的模块被引用后会生成一个pyc的文件(编译结果)下次被引用会首先读取pyc结尾的文件,直接载入,免得重复编译
Python字符类型
type() 查看字符类型
1、数字
int整型
long长整型(Python3以后没有长整型类型)
float浮点型
complex复数
2、布尔值
true and false
1 and 0
3、字符串
string
4、bytes 字节类型
字符串与二进制字节之间的相互转换
string.encode(encoding="utf-8") 字符串转换成二进制字节
bytes.decode(encoding="utf-8") 二进制转换成字符串
三元运算
result = a1 if condition else a2