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)
相关推荐
新子y1 分钟前
【小白笔记】最大交换 (Maximum Swap)问题
笔记·python
程序员爱钓鱼1 小时前
Python编程实战 · 基础入门篇 | Python的缩进与代码块
后端·python
earthzhang20212 小时前
【1028】字符菱形
c语言·开发语言·数据结构·c++·算法·青少年编程
pr_note2 小时前
python|if判断语法对比
python
earthzhang20214 小时前
第3讲:Go垃圾回收机制与性能优化
开发语言·jvm·数据结构·后端·性能优化·golang
apocelipes4 小时前
golang unique包和字符串内部化
java·python·性能优化·golang
纵有疾風起5 小时前
C++——类和对象(3)
开发语言·c++·经验分享·开源
Geoking.5 小时前
NumPy zeros() 函数详解
python·numpy
Full Stack Developme5 小时前
java.text 包详解
java·开发语言·python
文火冰糖的硅基工坊5 小时前
[嵌入式系统-135]:主流AIOT智能体开发板
开发语言·嵌入式·cpu