python 1.11 内置函数
python 关键字使用
1. this模块 pyhton介绍相关
import this
print(this)
'''
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
'''
2. python 关键字
import keyword
for i in keyword.kwlist:
print(i)
'''
## python 模块的导入关键字
from :导入包的关键字
import :导入函数的关键字
## 数据状态和数据对比的关键字
False True : 布尔类型的值
None : 代表空值 也是状态的一种,类的初始化函数返回空,函数没有return,返回值也是None
and : 逻辑运算符的一种 表示与的关系
or : 逻辑运算符的一种 表示或的关系
in : 成员运算符 for循环中使用
is : 判断值是不是相等的关键字
not : 取反的值 一般搭配 not in not is
## 条件判读语句关键字
if :if条件判断语句中使用,代表多个条件
elif :if条件判断语句中使用,代表多个条件
else :if条件判断语句中使用,代表不满足条件使用
while : 无限循环关键字
for : for循环中使用。
break : for while 循环中使用 可以结束循环体代码。
continue : for while 循环中使用 可以结束当次循环代码。
## 文件相关的关键字
with :使用在文件上下文管理中,with as 文件句柄
as :使用在文件上下文管理中,with as 文件句柄
##函数相关关键字
def :定义函数使用。
class :定义类名使用。
global :定义局部空间修改全局空间变量的关键字
nonlocal :定义局部空间修改上层空间变量的关键字
lambda :匿名函数的关键字
return :函数的返回值关键字
pass :含义是预先定义函数体代码。
yield :生成器的关键字
del :删除关键字 可以删除变量
## 捕捉异常的关键
try : 把出现异常的代码 缩进去执行。
except : 接受抛出的异常
assert
async
await
finally
raise
-------------------------------------------------
python中特殊意义的关键字
xargs : 动态参数
kwxargs :动态参数
内置函数
解释器帮助
help()
dir() 判断一个变量是否有属性的功能
callable() : 判断一个变量可以调用, 函数 类
内存相关
id() 判断内存的id 是否一致
== 判断2个变量值 是否一致
数据类型相关
dict()
bool()
int()
str()
tuple()
float()
bytes()
list()
set()
frozenset() : 冻结的集合 ,不可变集合
format() : 格式化字符串
enumerate() : 列表,元组 ,集合 添加索引值,
zip() : 拉链函数 两个不同数据类型进行一一对应
slice() :切片的规则存起来 不经常用
排序计算相关
bin()
hex()
oct()
all() 与运算
any() 或运算
abs() :取整型的数字的绝对值
min() min 求最小数
sum() 和
max() 求最大值
sorted() 排序从小大
map() : 两个列表的元素 相加
reversed()
len() 查看数据的长度
divmod() 返回余 和商
round() 浮点数 精度函数 精度模块 decimal
pow() # # 10 的2次方 除以3 取余数 pow(10,2,3)
注意 字典的比较是 值的比较 ,返回的是键 排序的是根据 字符在uincode的编码的数字排序
hash() : 一般是用hashlib
字符编码
ascii()
chr() 转ascii码 数字转字符串
ord() 字符转数字 适用场景 判断输入的用户名是否汉含有特俗字符
ord() print(ord('A')) # 等于65
输入输出
open() 文件的函数
input()
print() 打印内容
函数相关
globals()
locals()
eval() : 运行字符内的表达式
exec() : 行储存在字符串或文件中的 Python 语句
@装饰器 只要是可调用的就可以是装饰器,那么装饰器也可以是类名, 被装饰对象也可以是任意可调用对象
生成器
range()
iter()
next()
filter()
类相关
property()
staticmethod()
classmethod()
delattr()
getattr()
hasattr()
setattr()
super()
object()
issubclass()
isinstance()
type() : type(123)
__import__() # 使用 import time == m = __import__('time') m.sleep(10)
了解的
memoryview()
repr()
vars()
compile()
complex()
breakpoint()
bytearray()
浙公网安备 33010602011771号