21-removeprefix/removesuffix:匹配才移除

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

开始练习 →

22-count:不计算重叠匹配

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

开始练习 →

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

语法讲解 今天学: 字符串的字典序比较 print("Z" < "a") print("ab" < "aB") 小练习 运行下面代码后输出是

开始练习 →

24-难度5:format_map + __missing__

语法讲解 今天学: format_map 与 __missing__ class D(dict): def __missing__(self, key): return "?" tpl = &q

开始练习 →

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

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

开始练习 →

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

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

开始练习 →

27-难度5:translate 同时替换与删除

语法讲解 今天学: translate:替换 + 删除 s = "Hello World" table = str.maketrans({" ": "_"}, "&quo

开始练习 →

28-字符串拼接:join 还是 +(概念题)

语法讲解 今天学: 字符串拼接的性能常识 # 概念示例(不要求运行) parts = ["a"] * 10000 s = "".join(parts) 小练习 当你要把很多小字符串拼成一个大字

开始练习 →

29-输入题:strip 后统计长度

语法讲解 今天学: 输入字符串处理:strip + len s = input() s = s.strip() print(len(s)) 小练习 输入为:␠␠hello␠␠(两端各两个空格)。运行下面代码后输出是什么? s = i

开始练习 →

30-输入题:title 首字母大写

语法讲解 今天学: title 的用法 s = input() print(s.title()) 小练习 输入为:hello world。运行下面代码后输出是什么? s = input() print(s.title())

开始练习 →