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)
相关推荐
Scott9999HH4 小时前
【IIoT流量实战】蒸汽管道阀门全关却仍有流量?用 Python 实现涡街信号 FFT 频谱分析与温压全补偿积算网关,深度拆解靠谱的涡街流量计厂家硬核技术标准
开发语言·python
码智社5 小时前
AES加密原理详解及Java实现加解密实战
java·开发语言
AI云海5 小时前
python 列表、元组、集合和字典
开发语言·python
二十雨辰6 小时前
[爬虫]-Urllib
爬虫·python
萧瑟余晖6 小时前
JDK 26 新特性详解
java·开发语言
马优晨7 小时前
Freemarker 完整讲解(后端 Java 模板引擎)
java·开发语言·freemarker·freemarker 完整讲解·freemarker模板引擎
玉鸯8 小时前
Agent Hook:在概率推理之上,为 Agent 叠加确定性控制
python·langchain·agent
weixin_446260858 小时前
HACO:面向动态部署环境的对冲式智能计算可靠多智能体调度框架
后端·python·flask
我的xiaodoujiao8 小时前
API 接口自动化测试详细图文教程学习系列32--Allure测试报告2
python·学习·测试工具·pytest