Python: Unicode Tutorial 🐍

By Xah Lee. Date: . Last updated: .

This page describe working with unicode in python 3.

Python 2 Unicode Tutorial

For Python 2, see Python 2: Unicode Tutorial

Unicode Basics

Python Source Code Encoding

Unicode in String

Python 3's string is a sequence of unicode characters. You do not need the u in u"", but you can add it for familiarity with python 2. The u has no meaning.

Unicode Characters in Variable and Function Names

Python 3 allows Unicode characters in variable and function names, but they must be letter characters. Non-letter characters are not allowed. [see What Characters Are Unicode Letter]

def φ(n):
    return n+1

α = 4
print(φ(α))
# 5
♥ = 4

print(♥)

#     ♥ = 4
#     ^
# SyntaxError: invalid character in identifier

Unicode Characters Search

Python Unicode

Python

Overview

Help

String

Arithmetic

Boolean

Conditional

Loop, Iteration

Data Structure

Function and Class

Module

Misc

Regex

Text Processing

Web

Misc