Skip to content

字符串基础与进阶

本章讲解 Python 字符串的基础知识和进阶技巧。


章节导航

章节文件主题
0101-字符串基础.md创建、索引、切片、常用方法
0202-字符串进阶.md编码、正则表达式、实用技巧

核心知识点

创建字符串

  • 单引号、双引号、三引号
  • f-string 格式化

索引和切片

  • 正向索引从 0,反向索引从 -1
  • 切片 [start:end:step]

常用方法

  • find/replace/split/join
  • lower/upper/strip

正则表达式

  • re.findall() / re.sub() / re.match()
  • 常用模式:\d \w \s . * + ?