python的字符串

字符串

复制代码
#### 简单操作

*

  ##### 创建

  * 利用 ' ' 或 " " 将字符或数字包裹起来的都为字符串
    * a="你好"

<!-- -->

*

  ##### 格式化字符串

  * ![](https://img-blog.csdnimg.cn/img_convert/64e649079331977c0d3cbea9b289e265.png)

    ![](https://img-blog.csdnimg.cn/img_convert/6a83abb631ba35419bca66536d6c9454.png)

<!-- -->

*

  ##### 元组的字符格式化

  * ![](https://img-blog.csdnimg.cn/img_convert/af349ce6b6ca98b702d2a95a98de90b6.png)

<!-- -->

*

  ##### 字符串格式化函数

  * srt.format()
    * ![](https://img-blog.csdnimg.cn/img_convert/7570dec489c8061a9423111840f5b85f.png)

      ![](https://img-blog.csdnimg.cn/img_convert/a1967436114b9ede2a11d976a8ec5c22.png)

<!-- -->

*

  ##### f格式化

  * ![](https://img-blog.csdnimg.cn/img_convert/32de44a124a96defea29008e23a8ee85.png)

    ![](https://img-blog.csdnimg.cn/img_convert/09cc362f9b1ca8c58885f707e715805d.png)

<!-- -->

*

  ##### 方法

  * split()//指定分割符经行分割
    * ![](https://img-blog.csdnimg.cn/img_convert/bfdd1eb053e784a94aad8243ab65af8f.png)

  <!-- -->

  * strip()//指定移除字符头尾的字符
    * ![](https://img-blog.csdnimg.cn/img_convert/ca942e59d2bb82bbd7e35b5fa507038b.png)

  <!-- -->

  * join()//指定序列中的字符连接成新的字符串
    * ![](https://img-blog.csdnimg.cn/img_convert/f96e2a2450d4a5aecdb8795694b18824.png)

  <!-- -->

  * find()//检测是否有子字符串
    * ![](https://img-blog.csdnimg.cn/img_convert/2ede3669985c0a6de8d566b23ae4e5a4.png)

  <!-- -->

  * lower()//将所有大写转换为小写返回
    * ![](https://img-blog.csdnimg.cn/img_convert/43f439283b46f2bb6c3b282836eafd8d.png)

  <!-- -->

  * upper()//将小写转换为大写
    * ![](https://img-blog.csdnimg.cn/img_convert/829916685bffeaae52f47526c4c02388.png)

  <!-- -->

  * replace()//替换字符
    * ![](https://img-blog.csdnimg.cn/img_convert/d3bf130d588f897ad579bfed756a7798.png)

  <!-- -->

  * translate()//用于替换字符串中的字符
    * ![](https://img-blog.csdnimg.cn/img_convert/9e89330ff49819173fddcf269b89693c.png)

      ![](https://img-blog.csdnimg.cn/img_convert/bbfb6f494f53705d47318f8f34330799.png)
相关推荐
zone77399 小时前
001:简单 RAG 入门
后端·python·面试
F_Quant9 小时前
🚀 Python打包踩坑指南:彻底解决 Nuitka --onefile 配置文件丢失与重启报错问题
python·操作系统
允许部分打工人先富起来10 小时前
在node项目中执行python脚本
前端·python·node.js
IVEN_11 小时前
Python OpenCV: RGB三色识别的最佳工程实践
python·opencv
haosend11 小时前
AI时代,传统网络运维人员的转型指南
python·数据网络·网络自动化
曲幽12 小时前
不止于JWT:用FastAPI的Depends实现细粒度权限控制
python·fastapi·web·jwt·rbac·permission·depends·abac
IVEN_1 天前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发
python·全栈
Ray Liang1 天前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮1 天前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
千寻girling1 天前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python