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)) 小练习 运行下面代码后输出是什么?

阅读更多 →
06-split:maxsplit 的含义

06-split:maxsplit 的含义

语法讲解 今天学: split 的 maxsplit s = "a,b,c,d" parts = s.split(",", 2) print(len(parts

阅读更多 →
05-strip:指定字符集合

05-strip:指定字符集合

语法讲解 今天学: strip 的两种用法 s = "!!!hello!!!" print(s.strip("!")) t = "oohhehoo&

阅读更多 →
04-find vs index:找不到时差异

04-find vs index:找不到时差异

语法讲解 今天学: find / index 的差异 s = "hello" print(s.find("x")) try: print(s.index

阅读更多 →
03-字符串不能切片赋值

03-字符串不能切片赋值

语法讲解 今天学: 尝试修改字符串会触发异常 s = "cat" try: s[0] = "b" except Exception as e:

阅读更多 →
02-切片:start/end/step 的边界

02-切片:start/end/step 的边界

语法讲解 今天学: 字符串切片的边界与反向切片 s = "abcdef" print(s[0:6:2]) print(s[-1:2:-1]) 小练习 运行下面代码后输出是什

阅读更多 →
01-字符串不可变:+= 会发生什么

01-字符串不可变:+= 会发生什么

语法讲解 今天学: 字符串不可变与拼接 s = "Hi" t = s s += "!" print(s is t) print(s) 小练习 运行下面代

阅读更多 →