<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>字符串 on 老张开工了</title>
    <link>/%E5%AD%97%E7%AC%A6%E4%B8%B2/</link>
    <description>Recent content in 字符串 on 老张开工了</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Mon, 04 May 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="/%E5%AD%97%E7%AC%A6%E4%B8%B2/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>字符串操作深入</title>
      <link>/posts/2026/05/string-operations/</link>
      <pubDate>Mon, 04 May 2026 00:00:00 +0000</pubDate>
      <guid>/posts/2026/05/string-operations/</guid>
      <description>字符串是 Python 中使用最频繁的数据类型之一。无论是从用户获取输入、读写文件、处理网络数据，还是生成报告，字符串操作无处不在。Python 的字符串处理能力非常强大，掌握好字符串操作能让你在处理文本时事半功倍。&#xA;字符串基础 创建字符串 # 四种创建方式 s1 = &amp;#39;单引号字符串&amp;#39; s2 = &amp;#34;双引号字符串&amp;#34; s3 = &amp;#39;&amp;#39;&amp;#39;三单引号 支持换行&amp;#39;&amp;#39;&amp;#39; s4 = &amp;#34;&amp;#34;&amp;#34;三双引号 也支持换行&amp;#34;&amp;#34;&amp;#34; print(s1) # 单引号字符串 print(s2) # 双引号字符串 print(s3) # 三单引号\n支持换行 单引号 vs 双引号 两种方式完全等价，选择标准是方便性：&#xA;# 字符串本身包含单引号时，用双引号更省事 msg1 = &amp;#34;It&amp;#39;s a beautiful day&amp;#34; # 不用转义 msg2 = &amp;#39;It\&amp;#39;s a beautiful day&amp;#39; # 需要转义 # 字符串本身包含双引号时，用单引号更省事 msg3 = &amp;#39;他说：&amp;#34;你好&amp;#34;&amp;#39; msg4 = &amp;#34;他说：\&amp;#34;你好\&amp;#34;&amp;#34; 字符串索引与切片 索引 Python 字符串支持正索引（从 0 开始）和负索引（从 -1 开始）：&#xA;text = &amp;#34;Python&amp;#34; # 正索引（从 0 到 length-1） print(text[0]) # P print(text[1]) # y print(text[5]) # n # 负索引（从 -1 到 -length） print(text[-1]) # n（最后一个字符） print(text[-2]) # o（倒数第二个） print(text[-6]) # P（第一个字符） # 索引越界 # print(text[100]) # IndexError: string index out of range 切片（Slicing） 切片是 Python 最强大的特性之一，语法为 [start:stop:step]：</description>
    </item>
  </channel>
</rss>
