Skip to content

Commit de3bd9c

Browse files
author
暮晨
committed
EX.Half triple-quoted strings
1 parent 9eba4a3 commit de3bd9c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ So, here we go...
3838
- [> The surprising comma/意外的逗号](#-the-surprising-comma意外的逗号)
3939
- [> Backslashes at the end of string/字符串末尾的反斜杠](#-backslashes-at-the-end-of-string字符串末尾的反斜杠)
4040
- [> not knot!/别纠结!](#-not-knot别纠结)
41-
- [> Half triple-quoted strings](#-half-triple-quoted-strings)
41+
- [> Half triple-quoted strings/三个引号](#-half-triple-quoted-strings三个引号)
4242
- [> Midnight time doesn't exist?](#-midnight-time-doesnt-exist)
4343
- [> What's wrong with booleans?](#-whats-wrong-with-booleans)
4444
- [> Class attributes and instance attributes](#-class-attributes-and-instance-attributes)
@@ -703,28 +703,28 @@ SyntaxError: invalid syntax
703703
704704
---
705705
706-
### > Half triple-quoted strings
706+
### > Half triple-quoted strings/三个引号
707707
708708
**Output:**
709709
```py
710710
>>> print('wtfpython''')
711711
wtfpython
712712
>>> print("wtfpython""")
713713
wtfpython
714-
>>> # The following statements raise `SyntaxError`
714+
>>> # 下面的语句会抛出 `SyntaxError` 异常
715715
>>> # print('''wtfpython')
716716
>>> # print("""wtfpython")
717717
```
718718
719-
#### 💡 Explanation:
720-
+ Python supports implicit [string literal concatenation](https://docs.python.org/2/reference/lexical_analysis.html#string-literal-concatenation), Example,
719+
#### 💡 说明:
720+
+ Python 提供隐式的[字符串链接](https://docs.python.org/2/reference/lexical_analysis.html#string-literal-concatenation), 例如,
721721
```
722722
>>> print("wtf" "python")
723723
wtfpython
724724
>>> print("wtf" "") # or "wtf"""
725725
wtf
726726
```
727-
+ `'''` and `"""` are also string delimiters in Python which causes a SyntaxError because the Python interpreter was expecting a terminating triple quote as delimiter while scanning the currently encountered triple quoted string literal.
727+
+ `'''` `"""` 在 Python中也是字符串定界符, Python 解释器在先遇到三个引号的的时候会尝试再寻找三个终止引号作为定界符, 如果不存在则会导致 `SyntaxError` 异常.
728728
729729
---
730730

0 commit comments

Comments
 (0)