当前位置:  首页>> 技术小册>> Python合辑4-130个字符串操作示例

在 Python 中以多行方式连接字符串

  1. str1 = "This is a demo string"
  2. str2 = "This is another demo string"
  3. strz = ("This is a line\n" +
  4. str1 + "\n" +
  5. "This is line 2\n" +
  6. str2 + "\n" +
  7. "This is line 3\n")
  8. print(strz)

Output:

  1. This is a line
  2. This is a demo string
  3. This is line 2
  4. This is another demo string
  5. This is line 3

该分类下的相关小册推荐: