16-转义与原始字符串:长度陷阱

16-转义与原始字符串:长度陷阱

语法讲解 今天学: 转义与原始字符串 s1 = "a\nb" s2 = r"a\nb" print(s1) print(len(s2)) 小练习 运行下

阅读更多 →
15-format:补零与右对齐

15-format:补零与右对齐

语法讲解 今天学: format 格式控制 n = 7 print("{:03d}|{:>3d}".format(n, n)) 小练习 运行下面代码后输出是什么? n

阅读更多 →
14-isdigit/isdecimal:全角数字与罗马数字

14-isdigit/isdecimal:全角数字与罗马数字

语法讲解 今天学: 数字相关的字符串判定 a = "12" b = "Ⅻ" print(a.isdigit(), b.isdigit()) print(a.is

阅读更多 →
13-大小写:swapcase 与 title

13-大小写:swapcase 与 title

语法讲解 今天学: swapcase / title s = "Hello Python" print(s.swapcase()) print(s.title()) 小练习

阅读更多 →
12-translate:批量字符替换

12-translate:批量字符替换

语法讲解 今天学: translate 批量字符替换 table = str.maketrans({"e": "3", "o": "

阅读更多 →
11-replace:count 限制替换次数

11-replace:count 限制替换次数

语法讲解 今天学: replace 的 count 参数 s = "banana" print(s.replace("a", "A", 2)

阅读更多 →
10-join:生成器表达式也可以

10-join:生成器表达式也可以

语法讲解 今天学: join + 生成器表达式 pairs = [("a", 1), ("b", 2), ("c", 3)] print(&

阅读更多 →
09-join:元素必须都是字符串

09-join:元素必须都是字符串

语法讲解 今天学: join 的类型要求 try: print("-".join(["a", 1, "b"])) except Ex

阅读更多 →
08-partition:永远返回三段

08-partition:永远返回三段

语法讲解 今天学: partition 的固定三段结构 print("user=tom".partition("=")) print("abc&quo

阅读更多 →
07-rsplit:从右边开始切分

07-rsplit:从右边开始切分

语法讲解 今天学: rsplit 的用法 s = "a,b,c,d" print(s.rsplit(",", 2)) 小练习 运行下面代码后输出是什么?

阅读更多 →