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