Total Views:
python 数据类型
和绝大多数的文件或编程语言一样
基础的: num str None 复杂的: list, dict, set
python 函数中, 参数的定义顺序
| |
python 类知识点
| |
f-string使用
数字 格式化
| 需求 | f-string (推荐) |
|---|---|
| 保留2位小数 | “f”"{pi:.2f}""" |
| 千位分隔符 | “f”"{num:,}""" |
| 百分比(1位) | “f”"{ratio:.1%}""" |
| 补零(总宽5) | “f”"{num:05d}""" |
| 右对齐(总宽10) | “f”"{num:>10}""" |
repr !r的用法
| |
多行import, 换行
| |
except
| |
* 和 **
unpack
| |
[] 和 {}
| |
传参
| |
多list
| |
set操作
| |
其他常用 - collection. - Counter() - 统计个数神器 - most_comon() - pop - update - deque() - 双端队列 - 1 - append() - appendleft() - 2 - popleft() - pop() - clear() - namedtuple - 创建一个结构体的东西 - 不可修改 - 简单数据 - 方法 - 创建 - _make() - _replace() - 返回新实例 - 查看 - _asdict() - 返回字典 - _fields - 所有字段 - orderdict() - defaultdict(lambda:“none”) - 为不存在的 key 设置默认值 - itertools. - 排列组合 - 排列 - permutations() - 不放回,元素不重复 - product() - 多组 - 组合 - combinations - 不放回,元素不重复 - combinations_with_replacement() - 多组 - 1 - 使用 for - 使用 list() - repeat() - cycle() - dataclass - 可以修改 - 较复杂数据