官术网_书友最值得收藏!

String quoting styles

Literal strings in Python are delimited by quotes:

>>> 'This is a string'

You can use single quotation marks, as we have above. Or you can use double quotation marks, as shown below:

>>> "This is also a string"

You must, however, be consistent. For example, you can't use a double quotation mark paired with a single quotation mark:

>>> "inconsistent'
File "<stdin>", line 1
"inconsistent'
^
SyntaxError: EOL while scanning string literal

Supporting both quoting styles allows you to easily incorporate the other quote character into the literal string without resorting to ugly escape character gymnastics:

>>> "It's a good thing."
"It's a good thing."
>>> '"Yes!", he said, "I agree!"'
'"Yes!", he said, "I agree!"'

Notice that the REPL exploits the same quoting flexibility when echoing the strings back to us.

主站蜘蛛池模板: 永新县| 伊春市| 梅河口市| 娱乐| 高阳县| 呼玛县| 广安市| 彰化市| 卓尼县| 三原县| 阆中市| 陇南市| 沙河市| 黄骅市| 河池市| 上虞市| 额尔古纳市| 青冈县| 勃利县| 揭西县| 亳州市| 霍山县| 临猗县| 灵川县| 宜昌市| 安丘市| 大城县| 韩城市| 搜索| 南京市| 诸暨市| 湛江市| 奇台县| 泽州县| 托里县| 酉阳| 九寨沟县| 武宁县| 大兴区| 都江堰市| 东丰县|