当前位置:  首页>> 技术小册>> Python合辑3-字符串用法深度总结

处理引号和撇号

撇号 (') 在 Python 中表示一个字符串。为了让 Python 知道不是在处理字符串,必须使用 Python 转义字符 ()。因此撇号在 Python 中表示为 '。与处理撇号不同,Python 中有很多处理引号的方法。它们包括以下内容:

  1. # 1. Represent string with single quote (`""`) and quoted statement with double quote (`""`)
  2. quotes_one = '"Friends don\'t let friends use minibatches larger than 32" - Yann LeCun'
  3. print(quotes_one)
  4. # 2. Represent string with double quote `("")` and quoted statement with escape and double quote `(\"statement\")`
  5. quotes_two = "\"Friends don\'t let friends use minibatches larger than 32\" - Yann LeCun"
  6. print(quotes_two)
  7. # 3. Represent string with triple quote `("""""")` and quoted statment with double quote ("")
  8. quote_three = """"Friends don\'t let friends use minibatches larger than 32" - Yann LeCun"""
  9. print(quote_three)

Output:

  1. "Friends don't let friends use minibatches larger than 32" - Yann LeCun
  2. "Friends don't let friends use minibatches larger than 32" - Yann LeCun
  3. "Friends don't let friends use minibatches larger than 32" - Yann LeCun

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