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)
相关推荐
FreeCode1 天前
一文了解LangGraph智能体设计开发过程:Thinking in LangGraph
python·langchain·agent
西柚小萌新1 天前
【深入浅出PyTorch】--9.使用ONNX进行部署并推理
人工智能·pytorch·python
nvd111 天前
SSE 流式输出与 Markdown 渲染实现详解
javascript·python
LDG_AGI1 天前
【推荐系统】深度学习训练框架(十):PyTorch Dataset—PyTorch数据基石
人工智能·pytorch·分布式·python·深度学习·机器学习
未来之窗软件服务1 天前
操作系统应用(三十三)php版本选择系统—东方仙盟筑基期
开发语言·php·仙盟创梦ide·东方仙盟·服务器推荐
是Dream呀1 天前
昇腾实战|算子模板库Catlass与CANN生态适配
开发语言·人工智能·python·华为
零匠学堂20251 天前
移动学习系统,如何提升企业培训效果?
java·开发语言·spring boot·学习·音视频
小杨快跑~1 天前
从装饰者到桥接再到工厂:模式组合的艺术
java·开发语言·设计模式
say_fall1 天前
C语言编程实战:每日一题:随机链表的复制
c语言·开发语言·链表
培根芝士1 天前
使用llm-compressor 对 Qwen3-14B 做 AWQ + INT4 量化
人工智能·python