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)
相关推荐
yujunl7 分钟前
重写了一个BOM查询的脚本
开发语言
溪语流沙9 分钟前
【Web全栈进阶】前端对接新契约:信封解包 + 统一错误处理
前端·vue.js·python·状态模式·fastapi
Python图像识别16 分钟前
56-【2027毕设】YOLO11X光安检危险物品检测系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·qt·课程设计
事圆则缓29 分钟前
Kotlin 集合与序列:给页面一份清楚的数据
开发语言·windows·kotlin
事圆则缓30 分钟前
Kotlin 异步与并发:从一次搜索请求走到状态流
android·开发语言·kotlin
winfredzhang36 分钟前
从零实现“照片按地理位置显示在矢量地图上”:Flask + SQLite + Leaflet 全栈实战
python·sqlite·flask
从小白到软工44 分钟前
4-3 项目-学生成绩管理系统(上)
c语言·开发语言·数据结构·经验分享·ai编程
外收内放1 小时前
Python基础语法练习题(72)
开发语言·python
无忧.芙桃1 小时前
C++语言原理与实践(十三):stack、queue 和 priority_queue的介绍与使用
开发语言·c++·栈·队列