程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Single, double, and triple quotation marks in Python

編輯:Python
  • There are single quotation marks and double quotation marks in the string
>>> "it's a string"
"it's a string"
  • There are double quotation marks and single quotation marks in the string
>>> 'it is "python"'
'it is "python"'
  • String has multiple lines with three quotation marks
>>> s='''it's a string '''
>>> s
"it's\na\nstring\n"
>>> print(s)
it's
a
string

If you use single or double quotation marks, you will get an error , Also note the newline character in the string .

  • Single quotation marks 、 Double quotation marks can also represent multiline strings , But you need to put a backslash after each line
>>> s='it\
is\
a\
strng\
'
>>> s
'itisastrng'
  • Escape backslash
    Such as : The string represented by single quotation marks has single quotation marks
>>> 'it\'s a string'
"it's a string"

other ( Ignore the following is Different colors )

>>> s='It\nis\tpython'
>>> s
'It\nis\tpython'
>>> print(s)
It
is python
  • Original string r
    Output whatever it is , You can find that the third line escapes the newline character into ordinary characters with the escape character
>>> s=r"this\nis\na\nstring"
>>> s
'this\\nis\\na\\nstring'
>>> print(s)
this\nis\na\nstring

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved