Error in user YAML: (<unknown>): could not find expected ':' while scanning a simple key at line 3 column 1
---
- oeasy Python 0464
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
本教程同步发布在:
个人网站: `https://oeasy.org`
蓝桥云课: `https://www.lanqiao.cn/courses/3584`
GitHub: `https://github.com/overmind1980/oeasy-python-tutorial`
Gitee: `https://gitee.com/overmind1980/oeasypython`
---
| 类型 |
含义 |
效果 |
| f-string |
formatted string |
可使用上下文变量 |
| r-string |
raw string |
保持原始 |
| fr-string |
raw formatted string |
可使用变量,其余保持原始 |
| b-string |
byte |
字节序列 |
| ''' ''' |
Triple-quoted string |
三引号 |
- r-string的作用是 保留raw格式的文本
- 我们可以根据这些规则
for align, text in zip("<^>", ["left", "center", "right"]):
print("{0:{fill}{align}16}".format(text, fill=align, align=align))






import time
width = 80
for percent in range(1,101):
print(f"\r{percent:>3d}%",end="")
time.sleep(0.1)

import time
width = 80
for percent in range(1,101):
print(f"\r{percent:>3d}%[",end="")
num = percent * (width - 6) // 100
print("=" * num, end="")
print(" " * (width - 7 - num), end="")
print("]", end="")
time.sleep(0.1)

import time
for i in range(1, 101):
print("\r", end="")
print("进度: {}%: ".format(i), "▓" * (i // 2), end="")
time.sleep(0.05)

import time
t = 60
start = time.perf_counter()
for i in range(t + 1):
finish = "▓" * i
need_do = "-" * (t - i)
progress = (i / t) * 100
dur = time.perf_counter() - start
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(progress, finish, need_do, dur), end="")
time.sleep(0.05)
| 格式字符串 |
变量 |
含义 |
对应格式 |
| {:^3.0f} |
progress |
进度百分比 |
局中 宽度为3 精度为0 浮点型 |
| {} |
finish |
完成位置 |
直出 |
| ->{} |
need_do |
待完成 |
直出 |
| {:.2f}s |
dur |
耗时 |
精度2位 浮点型 |


import time
from tqdm import tqdm
for i in tqdm(range(1, 60)):
"""
代码
"""
# 这代码部分 需要0.05s,循环执行60次
time.sleep(0.05)



- 本文来自 oeasy Python 系统教程。
- 想完整、扎实学 Python,
- 搜索 oeasy 即可。