Python: Unicode Escape Sequence
Unicode Escape sequence lets you embed unicode character into string, by their Codepoint or character name. There are the following forms:
\u4_digits_hex
-
A character whose
Unicode Codepoint is 4 hexadecimal digits or less. If less, must pad 0 in front.
import sys print(sys.version) # BLACK HEART SUIT, hexadecimal 2665 print("♥" == "\u2665")
\U8_digits_hex
-
A character whose Unicode Codepoint is more than 4
Hexadecimal
digits. If less than 8 digits, you must pad 0 in front to make a total of 8 digits.
import sys print(sys.version) # GRINNING CAT FACE WITH SMILING EYES, hexadecimal 1f638 print("😸" == "\U0001f638")
\N{name}
-
Unicode character named name
(To find a Unicode Codepoint and name, see Unicode Search 😄)
import sys print(sys.version) # BLACK HEART SUIT, hexadecimal 2665 print("♥" == "\N{BLACK HEART SUIT}")
Python, Unicode
Python, String
- Python: Quote String
- Python: Triple Quote String
- Python: Raw String
- Python: String Prefix Char
- Python: f-String (Format, Template)
- Python: String Escape Sequence
- Python: Unicode Escape Sequence
- Python: Print String
- Python: Print Without Newline
- Python: Convert to String
- Python: Join String
- Python: Format String
- Python: String Methods
- Python: Search Substring
- Python: Split String
- Python: String, Check Case, Char Class
- Python: Letter Case Conversion
- Python: Unicode 🐍
- Python 2: Unicode Tutorial