@@ -548,7 +548,7 @@ Standard C. The recognized escape sequences are:
548
548
+-----------------+---------------------------------+-------+
549
549
| Escape Sequence | Meaning | Notes |
550
550
+=================+=================================+=======+
551
- | ``\newline `` | Backslash and newline ignored | |
551
+ | ``\ `` \ <newline> | Backslash and newline ignored | \( 1) |
552
552
+-----------------+---------------------------------+-------+
553
553
| ``\\ `` | Backslash (``\ ``) | |
554
554
+-----------------+---------------------------------+-------+
@@ -570,53 +570,64 @@ Standard C. The recognized escape sequences are:
570
570
+-----------------+---------------------------------+-------+
571
571
| ``\v `` | ASCII Vertical Tab (VT) | |
572
572
+-----------------+---------------------------------+-------+
573
- | ``\ooo `` | Character with octal value | (1,3 ) |
573
+ | ``\ooo `` | Character with octal value | (2,4 ) |
574
574
| | *ooo * | |
575
575
+-----------------+---------------------------------+-------+
576
- | ``\xhh `` | Character with hex value *hh * | (2,3 ) |
576
+ | ``\xhh `` | Character with hex value *hh * | (3,4 ) |
577
577
+-----------------+---------------------------------+-------+
578
578
579
579
Escape sequences only recognized in string literals are:
580
580
581
581
+-----------------+---------------------------------+-------+
582
582
| Escape Sequence | Meaning | Notes |
583
583
+=================+=================================+=======+
584
- | ``\N{name} `` | Character named *name * in the | \( 4 ) |
584
+ | ``\N{name} `` | Character named *name * in the | \( 5 ) |
585
585
| | Unicode database | |
586
586
+-----------------+---------------------------------+-------+
587
- | ``\uxxxx `` | Character with 16-bit hex value | \( 5 ) |
587
+ | ``\uxxxx `` | Character with 16-bit hex value | \( 6 ) |
588
588
| | *xxxx * | |
589
589
+-----------------+---------------------------------+-------+
590
- | ``\Uxxxxxxxx `` | Character with 32-bit hex value | \( 6 ) |
590
+ | ``\Uxxxxxxxx `` | Character with 32-bit hex value | \( 7 ) |
591
591
| | *xxxxxxxx * | |
592
592
+-----------------+---------------------------------+-------+
593
593
594
594
Notes:
595
595
596
596
(1)
597
+ A backslash can be added at the end of a line to ignore the newline::
598
+
599
+ >>> 'This string will not include \
600
+ ... backslashes or newline characters.'
601
+ 'This string will not include backslashes or newline characters.'
602
+
603
+ The same result can be achieved using :ref: `triple-quoted strings <strings >`,
604
+ or parentheses and :ref: `string literal concatenation <string-concatenation >`.
605
+
606
+
607
+ (2)
597
608
As in Standard C, up to three octal digits are accepted.
598
609
599
610
.. versionchanged :: 3.11
600
611
Octal escapes with value larger than ``0o377 `` produce a :exc: `DeprecationWarning `.
601
612
In a future Python version they will be a :exc: `SyntaxWarning ` and
602
613
eventually a :exc: `SyntaxError `.
603
614
604
- (2 )
615
+ (3 )
605
616
Unlike in Standard C, exactly two hex digits are required.
606
617
607
- (3 )
618
+ (4 )
608
619
In a bytes literal, hexadecimal and octal escapes denote the byte with the
609
620
given value. In a string literal, these escapes denote a Unicode character
610
621
with the given value.
611
622
612
- (4 )
623
+ (5 )
613
624
.. versionchanged :: 3.3
614
625
Support for name aliases [# ]_ has been added.
615
626
616
- (5 )
627
+ (6 )
617
628
Exactly four hex digits are required.
618
629
619
- (6 )
630
+ (7 )
620
631
Any Unicode character can be encoded this way. Exactly eight hex digits
621
632
are required.
622
633
0 commit comments