26-难度5:split 产生空串,过滤再 join

26-难度5:split 产生空串,过滤再 join

语法讲解 今天学: split 后过滤空字符串再 join s = "a,,b,,,c," parts = [x for x in s.split(",") i

阅读更多 →
25-难度5:format 字段下标访问

25-难度5:format 字段下标访问

语法讲解 今天学: format 的字段访问能力(下标访问) user = {"name": "Bob"} nums = [42, 99] print(&quo

阅读更多 →
24-难度5:format_map + __missing__

24-难度5:format_map + __missing__

语法讲解 今天学: format_map 与 __missing__ class D(dict): def __missing__(self, key): return &qu

阅读更多 →
23-字符串比较:按 Unicode 字典序

23-字符串比较:按 Unicode 字典序

语法讲解 今天学: 字符串的字典序比较 print("Z" < "a") print("ab" < "aB"

阅读更多 →
22-count:不计算重叠匹配

22-count:不计算重叠匹配

语法讲解 今天学: count 的非重叠匹配 s = "aaaa" print(s.count("aa")) 小练习 运行下面代码后输出是什么? s =

阅读更多 →
21-removeprefix/removesuffix:匹配才移除

21-removeprefix/removesuffix:匹配才移除

语法讲解 今天学: removeprefix / removesuffix s = "https://example.com" print(s.removeprefix("

阅读更多 →
20-对齐:ljust/rjust/center

20-对齐:ljust/rjust/center

语法讲解 今天学: ljust / rjust / center s = "hi" print(s.ljust(5, ".")) print(s.rjust(5

阅读更多 →
19-splitlines:keepends=True

19-splitlines:keepends=True

语法讲解 今天学: splitlines 的 keepends 参数 s = "a\nb\r\nc" parts = s.splitlines(keepends=True) pri

阅读更多 →
18-decode:errors='ignore'

18-decode:errors='ignore'

语法讲解 今天学: decode errors='ignore' b = b"hi\xff" print(b.decode("utf-8", e

阅读更多 →
17-编码:UTF-8 字节长度

17-编码:UTF-8 字节长度

语法讲解 今天学: encode 后按字节计数 print(len("猫".encode("utf-8"))) print(len("猫咪"

阅读更多 →