01-字符串不可变:+= 会发生什么
语法讲解 今天学: 字符串不可变与拼接 s = "Hi" t = s s += "!" print(s is t) print(s) 小练习 运行下面代码后输出是什么?(多行输出请按真实换行提
02-切片:start/end/step 的边界
语法讲解 今天学: 字符串切片的边界与反向切片 s = "abcdef" print(s[0:6:2]) print(s[-1:2:-1]) 小练习 运行下面代码后输出是什么?(多行输出请按真实换行提交) s =
03-字符串不能切片赋值
语法讲解 今天学: 尝试修改字符串会触发异常 s = "cat" try: s[0] = "b" except Exception as e: print(type(e).__name
04-find vs index:找不到时差异
语法讲解 今天学: find / index 的差异 s = "hello" print(s.find("x")) try: print(s.index("x")) exc
05-strip:指定字符集合
语法讲解 今天学: strip 的两种用法 s = "!!!hello!!!" print(s.strip("!")) t = "oohhehoo" print(t.strip(
06-split:maxsplit 的含义
语法讲解 今天学: split 的 maxsplit s = "a,b,c,d" parts = s.split(",", 2) print(len(parts)) print(parts)
07-rsplit:从右边开始切分
语法讲解 今天学: rsplit 的用法 s = "a,b,c,d" print(s.rsplit(",", 2)) 小练习 运行下面代码后输出是什么? s = "a,b,c,d&q
08-partition:永远返回三段
语法讲解 今天学: partition 的固定三段结构 print("user=tom".partition("=")) print("abc".partition("=
09-join:元素必须都是字符串
语法讲解 今天学: join 的类型要求 try: print("-".join(["a", 1, "b"])) except Exception as e: pr
10-join:生成器表达式也可以
语法讲解 今天学: join + 生成器表达式 pairs = [("a", 1), ("b", 2), ("c", 3)] print("".join(f&q