Python的三个引号作用

Python的三个引号作用

  • 英文解释
    • 含义
    • 说明
      • 引用

英文解释

Python’s triple quotes comes to the rescue by allowing strings to span
multiple lines, including verbatim NEWLINEs, TABs, and any other
special characters. The syntax for triple quotes consists of three
consecutive single or double quotes.

含义

Python的三个引号允许字符串跨多行使用,包括换行,TAB和任何其他特殊字符。 三个引号包括单引号和多引号

说明

  1. 用于字符串跨行,不必使用拼接符号。

输入

  1 multi_line =  """
  2 nice to meet you!
  3     nice to meet you!
  4       nice to meet you!
  5 """
  6 print multi_line

输出

nice to meet you!
  nice to meet you!
    nice to meet you!
  1. 用于注释
  1 #!/bin/env python
  2 #coding:utf8
  3
  4 '''
  5 @desc: 计算两个数的和
  6 @param a: 加数a
  7 @param b: 加数b
  8 '''
  9 def sum(a, b):
 10     return a + b
 11 print sum(1, 2)

引用

Triple Quotes in Python - Tutorialspoint

你可能感兴趣的:(代码开发,python,字符串)