Python Tutorial
Python Tutorial
3.14.0rc3
01, 2025
1 3
2 Python 5
2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3 Python 7
3.1 Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.1.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.1.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4 15
4.1 if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2 for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.3 range() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.4 break continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.5 else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.6 pass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.7 match . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.9.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.9.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.9.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.9.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.9.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.9.6 Lambda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.9.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.9.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
5 31
5.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.1.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.1.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
i
5.1.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.2 del . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
5.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6 41
6.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.1.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.1.3 Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.3 dir() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
6.4.1 *. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
6.4.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
6.4.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7 49
7.1 . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7.1.1 .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
7.1.2 format() . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.1.3 . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.1.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.2.2 json . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8 57
8.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
8.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
8.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
9 67
9.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
9.2 Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
9.2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
9.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
9.3.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
9.3.2 Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
9.3.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
9.3.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
9.3.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
9.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
9.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
9.5.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
9.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
9.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
9.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
ii
9.9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
9.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10 79
10.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
10.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
10.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
10.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
10.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
10.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
10.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
10.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
10.9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
10.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
10.11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
10.12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
11 85
11.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
11.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
11.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
11.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
11.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
11.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
11.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
11.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
12 91
12.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
12.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
12.3 pip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
13 95
14 97
14.1 Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
14.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
15 99
15.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
16 105
16.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
16.1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
16.1.2 Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
16.1.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
16.1.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
A 107
B 123
B.1 Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
C 125
C.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
C.2 Python . . . . . . . . . . . . . . . . . . . . . . . . . . 126
C.2.1 PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 . . . . . . . . . . . . . 126
C.2.2 PYTHON 2.0 [Link] . . . . . . . . . . . . . . . . . . . . . 127
C.2.3 PYTHON 1.6.1 CNRI . . . . . . . . . . . . . . . . . . . . . . . . . 127
C.2.4 PYTHON 0.9.0 1.2 CWI . . . . . . . . . . . . . . . . . . . . . . 128
iii
C.2.5 ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON DOCUMENTATION . 129
C.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
C.3.1 Mersenne Twister . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
C.3.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
C.3.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
C.3.4 Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
C.3.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
C.3.6 UUencode UUdecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
C.3.7 XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
C.3.8 test_epoll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
C.3.9 Select kqueue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
C.3.10 SipHash24 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
C.3.11 strtod dtoa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
C.3.12 OpenSSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
C.3.13 expat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
C.3.14 libffi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
C.3.15 zlib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
C.3.16 cfuhash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
C.3.17 libmpdec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
C.3.18 W3C C14N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
C.3.19 mimalloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
C.3.20 asyncio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
C.3.21 Global Unbounded Sequences (GUS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
C.3.22 Zstandard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
D 143
145
iv
Python Tutorial, 3.14.0rc3
Python
Python
Python
Contents 1
Python Tutorial, 3.14.0rc3
2 Contents
CHAPTER 1
C/C++/Java
Python
Unix shell Windows shell
GUI C/C++/Java
Python Windows, macOS Unix
Python
shell Python C
Python Awk Perl
Python
Python Python
Python I/O
Tk
Python
3
Python Tutorial, 3.14.0rc3
Python
Python
Python
4 Chapter 1.
CHAPTER 2
Python
2.1
Python /usr/local/bin/python3.14 /usr/local/bin
Unix shell
python3.14
1
shell Python
Python /usr/local/python
Windows Microsoft Store Python python3.14
[Link] py setting-envvars Python
Unix Control-D Windows Control-Z
0 quit()
GNU Readline
Python Control-P
^P
-i
using-on-general
1 Unix Python 2.x Python 3.x python
5
Python Tutorial, 3.14.0rc3
2.1.1
sys argv
import sys sys.
argv[0] '-' [Link][0] '-' -c command
[Link][0] '-c' -m module [Link][0]
-c command -m module [Link]
2.1.2
tty interactive mode
>>>
...
$ python3.14
Python 3.14 (default, April 4 2024, 09:25:04)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
if
2.2
2.2.1
Python UTF-8
ASCII
UTF-8
UNIX ”shebang”
#!/usr/bin/env python3
# -*- coding: cp1252 -*-
6 Chapter 2. Python
CHAPTER 3
Python
»> ...
Python #
# #
Python
#
spam = 1 #
# ...
text = "# "
3.1 Python
Python >>>
3.1.1
+,
-, * / (()) :
>>> 2 + 2
4
>>> 50 - 5*6
20
>>> (50 - 5*6) / 4
5.0
>>> 8 / 5 #
1.6
( /) floor division //
%:
7
Python Tutorial, 3.14.0rc3
>>> 17 / 3 #
5.666666666666667
>>>
>>> 17 // 3 #
5
>>> 17 % 3 # %
2
>>> 5 * 3 + 2 # * +
17
1
Python **
>>> 5 ** 2 # 5
25
>>> 2 ** 7 # 2 7
128
>>> width = 20
>>> height = 5 * 9
>>> width * height
900
>>> n #
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'n' is not defined
Python
>>> 4 * 3.75 - 1
14.0
_ Python
3.1.2
Python str ”!”, ”rabbit”,
”Paris”, ”Got your back.” . ”Yay! :)” ('...')
2
("...")
1 ** - , -3**2 -(3**2) -9 9, (-3)**2
2 \n '...' "..."
" \'
8 Chapter 3. Python
Python Tutorial, 3.14.0rc3
\
:
>>> 'doesn\'t' # \' ...
"doesn't"
>>> "doesn't" # ...
"doesn't"
>>> '"Yes," they said.'
'"Yes," they said.'
>>> "\"Yes,\" they said."
'"Yes," they said.'
>>> '"Isn\'t," they said.'
'"Isn\'t," they said.'
\ r
>>> print('C:\some\name') # \n
C:\some
ame
>>> print(r'C:\some\name') # r
C:\some\name
\ FAQ
: """...""" '''...'''
\ :
>>> print("""\
... Usage: thingy [OPTIONS]
... -h Display this usage message
... -H hostname Hostname to connect to
... """)
Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
>>>
+ *
3.1. Python 9
Python Tutorial, 3.14.0rc3
0
>>> word = 'Python'
>>> word[0] # 0
'P'
>>> word[5] # 5
'n'
>>> word[-1] #
'n'
>>> word[-2] #
'o'
>>> word[-6]
'P'
-0 0 -1
:
>>> word[0:2] # 0 ( ) 2 ( )
'Py'
>>> word[2:5] # 2 ( ) 5 ( )
'tho'
0
>>> word[:2] # 2 ( )
'Py'
>>> word[4:] # 4 ( )
'on'
>>> word[-2:] # ( )
'on'
10 Chapter 3. Python
Python Tutorial, 3.14.0rc3
s[:i] + s[i:] s
0 n
n
+---+---+---+---+---+---+
| P | y | t | h | o | n |
+---+---+---+---+---+---+
0 1 2 3 4 5 6
-6 -5 -4 -3 -2 -1
0...6 i j i j
word[1:3]
2
>>> word[4:42]
'on'
>>> word[42:]
''
Python immutable
len()
>>> s = 'supercalifragilisticexpialidocious'
>>> len(s)
34
3.1. Python 11
Python Tutorial, 3.14.0rc3
textseq
string-methods
f-strings
formatstrings
[Link]()
old-string-formatting
%
3.1.3
Python
sequence
>>> squares[0] #
1
>>> squares[-1]
25
>>> squares[-3:] #
[9, 16, 25]
immutable , mutable
[Link]()
:
>>> [Link](216) # 6
>>> [Link](7 ** 3) # 7
>>> cubes
[1, 8, 27, 64, 125, 216, 343]
Python
:
12 Chapter 3. Python
Python Tutorial, 3.14.0rc3
( )
True
>>> [Link]("Alph")
>>> rgb
["Red", "Green", "Blue", "Alph"]
len()
3.2
Python
:
>>> #
>>> #
>>> a, b = 0, 1
>>> while a < 10:
( )
3.2. 13
Python Tutorial, 3.14.0rc3
( )
... print(a)
... a, b = b, a+b
...
0
1
1
2
3
5
8
• a b 0 1
C <
> == <= ) >= !=
• Python
• print()
>>> i = 256*256
>>> print('The value of i is', i)
The value of i is 65536
end ,
>>> a, b = 0, 1
>>> while a < 1000:
... print(a, end=',')
... a, b = b, a+b
...
0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,
14 Chapter 3. Python
CHAPTER 4
while Python
4.1 if
if
4.2 for
Python for C Pascal Python for Pascal
C
>>> #
>>> words = ['cat', 'window', 'defenestrate']
>>> for w in words:
... print(w, len(w))
...
( )
15
Python Tutorial, 3.14.0rc3
( )
cat 3
window 6
defenestrate 12
#
users = {'Hans': 'active', 'Éléonore': 'inactive', ' ': 'active'}
#
for user, status in [Link]().items():
if status == 'inactive':
del users[user]
#
active_users = {}
for user, status in [Link]():
if status == 'active':
active_users[user] = status
4.3 range()
range()
range(10) 10 10
range 0
range() len()
enumerate()
16 Chapter 4.
Python Tutorial, 3.14.0rc3
range
>>> range(10)
range(0, 10)
range()
iterable for
sum()
>>> sum(range(4)) # 0 + 1 + 2 + 3
6
list()
continue :
>>> for num in range(2, 10):
... if num % 2 == 0:
... print(f"Found an even number {num}")
... continue
... print(f"Found an odd number {num}")
...
Found an even number 2
Found an odd number 3
Found an even number 4
Found an odd number 5
Found an even number 6
Found an odd number 7
Found an even number 8
Found an odd number 9
4.5 else
for while break else break
else
for else break
while
break else
return else
for
else for if
else if if/if/if/else
if break
else
4.6 pass
pass
pass pass
4.7 match
match case C
Java JavaScript switch Rust Haskell
case
18 Chapter 4.
Python Tutorial, 3.14.0rc3
def http_error(status):
match status:
case 400:
return "Bad request"
case 404:
return "Not found"
case 418:
return "I'm a teapot"
case _:
return "Something's wrong with the internet"
# point (x, y)
match point:
case (0, 0):
print("Origin")
case (0, y):
print(f"Y={y}")
case (x, 0):
print(f"X={x}")
case (x, y):
print(f"X={x}, Y={y}")
case _:
raise ValueError("Not a point")
point
(x, y) = point
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def where_is(point):
match point:
case Point(x=0, y=0):
print("Origin")
case Point(x=0, y=y):
print(f"Y={y}")
case Point(x=x, y=0):
print(f"X={x}")
case Point():
print("Somewhere else")
case _:
print("Not a point")
dataclass
__match_args__ (”x”, ”y”)
y var
4.7. match 19
Python Tutorial, 3.14.0rc3
Point(1, var)
Point(1, y=var)
Point(x=1, y=var)
Point(y=var, x=1)
class Point:
__match_args__ = ('x', 'y')
def __init__(self, x, y):
self.x = x
self.y = y
match points:
case []:
print("No points")
case [Point(0, 0)]:
print("The origin")
case [Point(x, y)]:
print(f"Single point {x}, {y}")
case [Point(0, y1), Point(0, y2)]:
print(f"Two on the Y axis at {y1}, {y2}")
case _:
print("Something else")
if match case
match point:
case Point(x, y) if x == y:
print(f"Y=X at {x}")
case Point(x, y):
print(f"Not on the diagonal")
• as
p2
20 Chapter 4.
Python Tutorial, 3.14.0rc3
( )
RED = 'red'
GREEN = 'green'
BLUE = 'blue'
match color:
case [Link]:
print("I see red!")
case [Link]:
print("Grass is green")
case [Link]:
print("I'm feeling the blues :(")
PEP 636
4.8
def
docstring
Python
global
nonlocal
>>> fib
<function fib at 10042ed0>
>>> f = fib
>>> f(100)
0 1 1 2 3 5 8 13 21 34 55 89
fib
return None ( )
None print() :
1
4.8. 21
Python Tutorial, 3.14.0rc3
>>> fib(0)
>>> print(fib(0))
None
Python
• return return None
None
• [Link](a) result
[Link] obj methodname
append()
result = result + [a]
4.9
4.9.1
in
22 Chapter 4.
Python Tutorial, 3.14.0rc3
i = 5
def f(arg=i):
print(arg)
i = 6
f()
print(f(1))
print(f(2))
print(f(3))
[1]
[1, 2]
[1, 2, 3]
4.9.2
kwarg=value
parrot(1000) # 1
parrot(voltage=1000) # 1
parrot(voltage=1000000, action='VOOOOOM') # 2
parrot(action='VOOOOOM', voltage=1000000) # 2
parrot('a million', 'bereft of life', 'jump') # 3
parrot('a thousand', state='pushing up the daisies') # 1 1
parrot() #
parrot(voltage=5.0, 'dead') #
parrot(110, voltage=220) #
parrot(actor='John Cleese') #
4.9. 23
Python Tutorial, 3.14.0rc3
actor parrot
parrot(voltage=1000)
**name typesmapping
**name *name *name
**name *name
4.9.3
Python
24 Chapter 4.
Python Tutorial, 3.14.0rc3
/ *
/ *
/ /
/
/ *
standard_arg
>>> standard_arg(2)
2
>>> standard_arg(arg=2)
2
pos_only_arg /
>>> pos_only_arg(1)
1
>>> pos_only_arg(arg=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: pos_only_arg() got some positional-only arguments passed as keyword arguments:
,→'arg'
kwd_only_arg *
>>> kwd_only_arg(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: kwd_only_arg() takes 0 positional arguments but 1 was given
( )
4.9. 25
Python Tutorial, 3.14.0rc3
( )
>>> kwd_only_arg(arg=3)
3
>>> combined_example(1, 2, 3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: combined_example() takes 2 positional arguments but 3 were given
True 'name'
/ name 'name'
**kwds
• API API
26 Chapter 4.
Python Tutorial, 3.14.0rc3
4.9.4
variadic *args
4.9.5
range()
start stop *
**
4.9.6 Lambda
lambda lambda a, b: a+b Lambda
lambda
lambda [Link]()
key lambda :
4.9. 27
Python Tutorial, 3.14.0rc3
>>> pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
>>> [Link](key=lambda pair: pair[1])
>>> pairs
[(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]
4.9.7
Python Python
4.9.8
PEP 3107 PEP 484
__annotations__
-> def
:
4.10
Python
28 Chapter 4.
Python Tutorial, 3.14.0rc3
• 4
4
• 79
•
•
•
• a = f(1, 2) + g(3, 4)
• UpperCamelCase
lowercase_with_underscores self ( )
• Python UTF-8 ASCII
• ASCII
4.10. 29
Python Tutorial, 3.14.0rc3
30 Chapter 4.
CHAPTER 5
5.1
[Link](x)
a[len(a):] = [x]
[Link](iterable)
iterable a[len(a):] = iterable
[Link](i, x)
[Link](0, x)
[Link](len(a), x) [Link](x)
[Link](x)
x ValueError
[]
[Link]( i )
[Link]()
IndexError
[Link]()
del a[:]
[ [
[Link](x , start , end ]])
x ValueError
start end
start
[Link](x)
x
[Link](* (Keyword-only parameters separator (PEP 3102)), key=None, reverse=False)
sorted()
31
Python Tutorial, 3.14.0rc3
[Link]()
[Link]()
a[:]
5.1.1
append() pop() :
1 d->insert("a")->remove("b")->sort();
32 Chapter 5.
Python Tutorial, 3.14.0rc3
5.1.2
[Link]
5.1.3
>>> squares = []
>>> for x in range(10):
... [Link](x**2)
...
>>> squares
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
for for
if for if
>>> combs = []
>>> for x in [1,2,3]:
... for y in [3,1,4]:
... if x != y:
... [Link]((x, y))
...
>>> combs
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
for if
5.1. 33
Python Tutorial, 3.14.0rc3
(x, y)
5.1.4
3x4 3 4
>>> matrix = [
... [1, 2, 3, 4],
... [5, 6, 7, 8],
... [9, 10, 11, 12],
... ]
for
:
>>> transposed = []
>>> for i in range(4):
... [Link]([row[i] for row in matrix])
...
>>> transposed
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
34 Chapter 5.
Python Tutorial, 3.14.0rc3
>>> transposed = []
>>> for i in range(4):
... # 3
... transposed_row = []
... for row in matrix:
... transposed_row.append(row[i])
... [Link](transposed_row)
...
>>> transposed
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
zip()
>>> list(zip(*matrix))
[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
5.2 del
del pop() del
:
>>> a = [-1, 1, 66.25, 333, 333, 1234.5]
>>> del a[0]
>>> a
[1, 66.25, 333, 333, 1234.5]
>>> del a[2:4]
>>> a
[1, 66.25, 1234.5]
>>> del a[:]
>>> a
[]
del
>>> del a
a del
5.3
typesseq Python
5.2. del 35
Python Tutorial, 3.14.0rc3
( )
>>> t[0] = 88888
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> #
>>> v = ([1, 2, 3], [3, 2, 1])
>>> v
([1, 2, 3], [3, 2, 1])
immutable
namedtuples mutable
0 1
>>> empty = ()
>>> singleton = 'hello', # <--
>>> len(empty)
0
>>> len(singleton)
1
>>> singleton
('hello',)
>>> x, y, z = t
5.4
Python
set() set() {} {}
>>> #
>>>
>>> a = set('abracadabra')
>>> b = set('alacazam')
( )
36 Chapter 5.
Python Tutorial, 3.14.0rc3
( )
>>> a # a
{'a', 'r', 'b', 'c', 'd'}
>>> a - b # a b
{'r', 'd', 'b'}
>>> a | b # a b
{'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}
>>> a & b # a b
{'a', 'c'}
>>> a ^ b # a b
{'r', 'd', 'b', 'm', 'z', 'l'}
5.5
Python ( typesmapping)
append() extend()
{}
del
list(d) sorted(d)
in
dict()
5.5. 37
Python Tutorial, 3.14.0rc3
5.6
items()
enumerate()
zip()
reversed()
sorted()
38 Chapter 5.
Python Tutorial, 3.14.0rc3
( )
orange
pear
5.7
while if
in not in
is is not
a < b == c a b b c
and or not
not or A and not B
or C (A and (not B)) or C
and or
A C B A and B and C C
Python C := C
== =
5.8
5.7. 39
Python Tutorial, 3.14.0rc3
Unicode
< >
0 0.0
TypeError
40 Chapter 5.
CHAPTER 6
Python Python
Python
Python .py
__name__ [Link]
def fib(n):
"""Write Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()
def fib2(n):
"""Return Fibonacci series up to n."""
result = []
a, b = 0, 1
while a < n:
[Link](a)
a, b = b, a+b
return result
Python
41
Python Tutorial, 3.14.0rc3
>>> [Link](1000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
>>> fibo.fib2(100)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
>>> fibo.__name__
'fibo'
6.1
import
1
( )
[Link]
import
import
:
fibo
as as
from
42 Chapter 6.
Python Tutorial, 3.14.0rc3
6.1.1
Python
__name__ "__main__"
if __name__ == "__main__":
import sys
fib(int([Link][1]))
main
$ python [Link] 50
0 1 1 2 3 5 8 13 21 34
6.1.2
spam sys.
builtin_module_names [Link]
[Link] [Link] :
•
• PYTHONPATH shell PATH
• site-packages site
sys-path-init
Python [Link]
6.1. 43
Python Tutorial, 3.14.0rc3
6.1.3 Python
Python __pycache__ [Link].
pyc version Python CPython 3.3 [Link]
__pycache__/[Link] Python
Python
Python
• compileall .pyc
• PEP 3147
6.2
Python Python ” ”
[Link] PYTHONPATH
PYTHONPATH
6.3 dir()
dir()
44 Chapter 6.
Python Tutorial, 3.14.0rc3
( )
['__name__', 'fib', 'fib2']
>>> dir(sys)
['__breakpointhook__', '__displayhook__', '__doc__', '__excepthook__',
'__interactivehook__', '__loader__', '__name__', '__package__', '__spec__',
'__stderr__', '__stdin__', '__stdout__', '__unraisablehook__',
'_clear_type_cache', '_current_frames', '_debugmallocstats', '_framework',
'_getframe', '_git', '_home', '_xoptions', 'abiflags', 'addaudithook',
'api_version', 'argv', 'audit', 'base_exec_prefix', 'base_prefix',
'breakpointhook', 'builtin_module_names', 'byteorder', 'call_tracing',
'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_info',
'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info',
'float_repr_style', 'get_asyncgen_hooks', 'get_coroutine_origin_tracking_depth',
'getallocatedblocks', 'getdefaultencoding', 'getdlopenflags',
'getfilesystemencodeerrors', 'getfilesystemencoding', 'getprofile',
'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval',
'gettrace', 'hash_info', 'hexversion', 'implementation', 'int_info',
'intern', 'is_finalizing', 'last_traceback', 'last_type', 'last_value',
'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks',
'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'pycache_prefix',
'set_asyncgen_hooks', 'set_coroutine_origin_tracking_depth', 'setdlopenflags',
'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr',
'stdin', 'stdout', 'thread_info', 'unraisablehook', 'version', 'version_info',
'warnoptions']
dir()
>>> a = [1, 2, 3, 4, 5]
>>> import fibo
>>> fib = [Link]
>>> dir()
['__builtins__', '__name__', 'a', 'fib', 'fibo', 'sys']
dir() builtins
6.3. dir() 45
Python Tutorial, 3.14.0rc3
( )
'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass',
'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview',
'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property',
'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice',
'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars',
'zip']
6.4
Python A.B A
B
NumPy Pillow
sound/
__init__.py sound
formats/
__init__.py
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
...
effects/
__init__.py
[Link]
[Link]
[Link]
...
filters/
__init__.py
[Link]
[Link]
[Link]
...
Python [Link]
import [Link]
[Link]
46 Chapter 6.
Python Tutorial, 3.14.0rc3
echo :
Import
echo echofilter() :
6.4.1 *
from [Link] import *
import __init__.py
__all__ from package import *
*
sound/effects/__init__.py
__all__ = [
"echo", # '[Link]'
"surround", # '[Link]'
"reverse", # !!! 'reverse' !!!
]
import [Link]
import [Link]
from [Link] import *
6.4. 47
Python Tutorial, 3.14.0rc3
import *
6.4.2
sound
[Link] [Link] echo from
[Link] import echo
from module import name import
surround :
Python
6.4.3
__path__ sequence
__init__.py
48 Chapter 6.
CHAPTER 7
7.1
: print()
write() [Link]
• / f F
{ } Python
• [Link]() { }
repr() str()
str() repr()
SyntaxError str() repr()
49
Python Tutorial, 3.14.0rc3
string [Link]
$x
7.1.1
f- f F {expression}
Python
pi
':'
50 Chapter 7.
Python Tutorial, 3.14.0rc3
= formatspec
7.1.2 format()
[Link]()
[Link]()
[Link]()
[Link]()
'[]'
table **
vars() :
>>> table = {k: str(v) for k, v in vars().items()}
>>> message = " ".join([f'{k}: ' + '{' + k +'};' for k in [Link]()])
>>> print([Link](**table))
__name__: __main__; __doc__: None; __package__: None; __loader__: ...
:
>>> for x in range(1, 11):
... print('{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x))
( )
7.1. 51
Python Tutorial, 3.14.0rc3
( )
...
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
[Link]() formatstrings
7.1.3
print()
[Link]()
[Link]() [Link]()
[Link](n)[:n]
[Link]()
>>> '12'.zfill(5)
'00012'
>>> '-3.14'.zfill(7)
'-003.14'
>>> '3.14159265359'.zfill(5)
'3.14159265359'
7.1.4
% ( ) format % values ( format )
format % values :
old-string-formatting
52 Chapter 7.
Python Tutorial, 3.14.0rc3
7.2
open() file object open(filename, mode,
encoding=None)
mode 'r'
'w' 'a'
'r+' mode
'r'
text mode
encoding encoding open() UTF-8
encoding="utf-8"
'b' binary mode bytes
encoding
Unix \n, Windows \r\n \n
\n
JPEG EXE
with
with try-finally
>>> #
>>> [Link]
True
with [Link]()
with [Link]()
>>> [Link]()
>>> [Link]()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file.
7.2.1
f
[Link](size)
size size size
size size size
[Link]() ''
>>> [Link]()
'This is the entire file.\n'
( )
7.2. 53
Python Tutorial, 3.14.0rc3
( )
>>> [Link]()
''
[Link]() \n
[Link]()
'\n'
>>> [Link]()
'This is the first line of the file.\n'
>>> [Link]()
'Second line of the file\n'
>>> [Link]()
''
list(f) [Link]()
[Link](string) string
[Link]()
b seek(0, 2)
offset [Link]() 0 offset
isatty() truncate()
54 Chapter 7.
Python Tutorial, 3.14.0rc3
7.2.2 json
read()
int() '123' 123
JSON
JSON
[Link](x, f)
x = [Link](f)
JSON
json
pickle -
pickle
7.2. 55
Python Tutorial, 3.14.0rc3
56 Chapter 7.
CHAPTER 8
8.1
Python
print() (':')
( <stdin>)
8.2
Python
>>> 10 * (1/0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
10 * (1/0)
~^~
ZeroDivisionError: division by zero
>>> 4 + spam*3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
4 + spam*3
^^^^
NameError: name 'spam' is not defined
( )
57
Python Tutorial, 3.14.0rc3
( )
>>> '2' + 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
'2' + 2
~~~~^~~
TypeError: can only concatenate str (not "int") to str
bltin-exceptions
8.3
Control-C KeyboardInterrupt
try
• except try
• try except
except try/except
• except try
try except
try try except
:
... except (RuntimeError, TypeError, NameError):
... pass
except ---
except B, C, D:
class B(Exception):
pass
class C(B):
pass
class D(C):
( )
58 Chapter 8.
Python Tutorial, 3.14.0rc3
( )
pass
except
args __str__()
.args
>>> try:
... raise Exception('spam', 'eggs')
... except Exception as inst:
... print(type(inst)) #
... print([Link]) # .args
... print(inst) # __str__ args
... #
... x, y = [Link] # args
... print('x =', x)
... print('y =', y)
...
<class 'Exception'>
('spam', 'eggs')
('spam', 'eggs')
x = spam
y = eggs
__str__() (’detail’)
BaseException Exception
Exception [Link]()
SystemExit KeyboardInterrupt
Exception
Exception :
import sys
try:
f = open('[Link]')
s = [Link]()
i = int([Link]())
except OSError as err:
print("OS error:", err)
except ValueError:
print("Could not convert data to an integer.")
except Exception as err:
print(f"Unexpected {err=}, {type(err)=}")
raise
8.3. 59
Python Tutorial, 3.14.0rc3
try try
:
8.4
raise
raise BaseException
Exception
raise
>>> try:
... raise NameError('HiThere')
... except NameError:
... print('An exception flew by!')
... raise
...
An exception flew by!
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
raise NameError('HiThere')
NameError: HiThere
60 Chapter 8.
Python Tutorial, 3.14.0rc3
8.5
except
:
>>> try:
... open("[Link]")
... except OSError:
... raise RuntimeError("unable to handle error")
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
open("[Link]")
~~~~^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '[Link]'
raise from :
# exc None
raise RuntimeError from exc
The above exception was the direct cause of the following exception:
from None :
>>> try:
... open('[Link]')
... except OSError:
... raise RuntimeError from None
...
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
raise RuntimeError from None
( )
8.5. 61
Python Tutorial, 3.14.0rc3
( )
RuntimeError
bltin-exceptions
8.6
Python
Exception
Error
8.7
try
>>> try:
... raise KeyboardInterrupt
... finally:
... print('Goodbye, world!')
...
Goodbye, world!
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
raise KeyboardInterrupt
KeyboardInterrupt
• try except
except finally
62 Chapter 8.
Python Tutorial, 3.14.0rc3
finally
8.8
with
with open("[Link]") as f:
for line in f:
print(line, end="")
8.9
ExceptionGroup
8.8. 63
Python Tutorial, 3.14.0rc3
except* except
except*
64 Chapter 8.
Python Tutorial, 3.14.0rc3
( )
| ExceptionGroup: group1 (1 sub-exception)
+-+---------------- 1 ----------------
| ExceptionGroup: group2 (1 sub-exception)
+-+---------------- 1 ----------------
| RecursionError: 4
+------------------------------------
>>>
>>> excs = []
... for test in tests:
... try:
... [Link]()
... except Exception as e:
... [Link](e)
...
>>> if excs:
... raise ExceptionGroup("Test Failures", excs)
...
8.10
add_note(note)
>>> try:
... raise TypeError('bad type')
... except Exception as e:
... e.add_note('Add some information')
... e.add_note('Add some more information')
... raise
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
raise TypeError('bad type')
TypeError: bad type
Add some information
Add some more information
>>>
8.10. 65
Python Tutorial, 3.14.0rc3
( )
| File "<stdin>", line 1, in <module>
| raise ExceptionGroup('We have some problems', excs)
| ExceptionGroup: We have some problems (3 sub-exceptions)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 3, in <module>
| f()
| ~^^
| File "<stdin>", line 2, in f
| raise OSError('operation failed')
| OSError: operation failed
| Happened in Iteration 1
+---------------- 2 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 3, in <module>
| f()
| ~^^
| File "<stdin>", line 2, in f
| raise OSError('operation failed')
| OSError: operation failed
| Happened in Iteration 2
+---------------- 3 ----------------
| Traceback (most recent call last):
| File "<stdin>", line 3, in <module>
| f()
| ~^^
| File "<stdin>", line 2, in f
| raise OSError('operation failed')
| OSError: operation failed
| Happened in Iteration 3
+------------------------------------
>>>
66 Chapter 8.
CHAPTER 9
Python
C++ public
virtual Modula-3
Smalltalk
Python C++ Modula-3 Python
C++
9.1
Python
Python
Pascal
9.2 Python
Python
Python
namespace Python
abs()
67
Python Tutorial, 3.14.0rc3
maximize
[Link] real z
[Link] modname funcname
1
Python
__main__
builtins
Python
3 4
•
•
•
•
nonlocal
nonlocal
Python
global nonlocal
9.2.1
global nonlocal
1 __dict__ __dict__
68 Chapter 9.
Python Tutorial, 3.14.0rc3
def scope_test():
def do_local():
spam = "local spam"
def do_nonlocal():
nonlocal spam
spam = "nonlocal spam"
def do_global():
global spam
spam = "global spam"
scope_test()
print("In global scope:", spam)
global spam
9.3
9.3.1
class ClassName:
< -1>
.
.
.
< -N>
(def ) if
---
---
( )
( )
( ClassName)
9.3. 69
Python Tutorial, 3.14.0rc3
9.3.2 Class
Python : [Link]
:
class MyClass:
""" """
i = 12345
def f(self):
return 'hello world'
MyClass.i MyClass.f
MyClass.i __doc__
: "A simple example class"
x = MyClass()
( )
__init__() :
def __init__(self):
[Link] = []
__init__() __init__()
:
x = MyClass()
__init__()
__init__()
9.3.3
Smalltalk ” ” C++ ” ”
x MyClass
16 :
[Link] = 1
while [Link] < 10:
[Link] = [Link] * 2
print([Link])
del [Link]
70 Chapter 9.
Python Tutorial, 3.14.0rc3
9.3.4
:
x.f()
xf = x.f
while True:
print(xf())
hello world
f()
x.f()
Python --- ...
x.f() MyClass.f(x) n
9.3.5
:
class Dog:
kind = 'canine' #
>>> d = Dog('Fido')
>>> e = Dog('Buddy')
>>> [Link] # Dog
'canine'
>>> [Link] # Dog
'canine'
>>> [Link] # d
'Fido'
>>> [Link] # e
'Buddy'
mutable
tricks Dog
:
9.3. 71
Python Tutorial, 3.14.0rc3
class Dog:
tricks = [] #
>>> d = Dog('Fido')
>>> e = Dog('Buddy')
>>> d.add_trick('roll over')
>>> e.add_trick('play dead')
>>> [Link] # Dog
['roll over', 'play dead']
class Dog:
>>> d = Dog('Fido')
>>> e = Dog('Buddy')
>>> d.add_trick('roll over')
>>> e.add_trick('play dead')
>>> [Link]
['roll over']
>>> [Link]
['play dead']
9.4
:
Python ---
C Python
C Python
---
---
72 Chapter 9.
Python Tutorial, 3.14.0rc3
#
def f1(self, x, y):
return min(x, x+y)
class C:
f = f1
def g(self):
return 'hello world'
h = g
f g h C C --- h g
self :
class Bag:
def __init__(self):
[Link] = []
object.__class__
9.5
:
class DerivedClassName(BaseClassName):
< -1>
.
.
.
< -N>
BaseClassName
:
class DerivedClassName([Link]):
9.5. 73
Python Tutorial, 3.14.0rc3
: DerivedClassName()
[Link](self, arguments)
BaseClassName
Python
• isinstance() : isinstance(obj, int) obj.__class__
int int True
9.5.1
Python :
DerivedClassName
Base1 Base1
Base2
super()
super
object
object
python_2.3_mro
9.6
Python Python
( _spam) API (
)
__spam
_classname__spam classname
74 Chapter 9.
Python Tutorial, 3.14.0rc3
:
class Mapping:
def __init__(self, iterable):
self.items_list = []
self.__update(iterable)
class MappingSubclass(Mapping):
MappingSubclass __update
Mapping _Mapping__update MappingSubclass
_MappingSubclass__update
9.7
Pascal ”record” C ”struct”
dataclasses:
@dataclass
class Employee:
name: str
dept: str
salary: int
Python
read()
readline()
9.7. 75
Python Tutorial, 3.14.0rc3
9.8
for :
Python
for iter() __next__()
__next__() StopIteration for
next() __next__() :
>>> s = 'abc'
>>> it = iter(s)
>>> it
<str_iterator object at 0x10c90e650>
>>> next(it)
'a'
>>> next(it)
'b'
>>> next(it)
'c'
>>> next(it)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
next(it)
StopIteration
__iter__()
__next__() __next__() __iter__()
self:
class Reverse:
""" """
def __init__(self, data):
[Link] = data
[Link] = len(data)
def __iter__(self):
return self
def __next__(self):
if [Link] == 0:
raise StopIteration
[Link] = [Link] - 1
return [Link][[Link]]
76 Chapter 9.
Python Tutorial, 3.14.0rc3
( )
m
a
p
s
9.9
yield next()
:
def reverse(data):
for index in range(len(data)-1, -1, -1):
yield data[index]
__iter__() __next__()
self.
index [Link]
StopIteration
9.10
9.9. 77
Python Tutorial, 3.14.0rc3
78 Chapter 9.
CHAPTER 10
10.1
os :
>>> import os
>>> [Link]() #
'C:\\Python314'
>>> [Link]('/server/accesslogs') #
>>> [Link]('mkdir today') # shell mkdir
0
>>> import os
>>> dir(os)
< >
>>> help(os)
< >
shutil :
10.2
glob :
79
Python Tutorial, 3.14.0rc3
10.3
sys argv
[Link] :
# [Link]
import sys
print([Link])
argparse
:
import argparse
parser = [Link](
prog='top',
description='Show top lines from each file')
parser.add_argument('filenames', nargs='+')
parser.add_argument('-l', '--lines', type=int, default=10)
args = parser.parse_args()
print(args)
10.4
sys stdin stdout stderr stdout
:
[Link]()
10.5
re
:
>>> import re
>>> [Link](r'\bf[a-z]*', 'which foot or hand fell fastest')
['foot', 'fell', 'fastest']
>>> [Link](r'(\b[a-z]+) \1', r'\1', 'cat in the the hat')
'cat in the hat'
80 Chapter 10.
Python Tutorial, 3.14.0rc3
10.6
math C :
random :
statistics :
SciPy <[Link]
10.7
[Link] URL
smtplib :
localhost
10.6. 81
Python Tutorial, 3.14.0rc3
10.8
datetime
>>> #
>>> from datetime import date
>>> now = [Link]()
>>> now
[Link](2003, 12, 2)
>>> [Link]("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.")
'12-02-03. 02 Dec 2003 is a Tuesday on the 02 day of December.'
>>> #
>>> birthday = date(1964, 7, 31)
>>> age = now - birthday
>>> [Link]
14368
10.9
zlib, gzip, bz2, lzma, zipfile tarfile :
>>> import zlib
>>> s = b'witch which has which witches wrist watch'
>>> len(s)
41
>>> t = [Link](s)
>>> len(t)
37
>>> [Link](t)
b'witch which has which witches wrist watch'
>>> zlib.crc32(s)
226805979
10.10
Python Python
timeit
:
>>> from timeit import Timer
>>> Timer('t=a; a=b; b=t', 'a=1; b=2').timeit()
0.57535828626024577
>>> Timer('a,b = b,a', 'a=1; b=2').timeit()
0.54962537085770791
10.11
doctest
doctest :
82 Chapter 10.
Python Tutorial, 3.14.0rc3
def average(values):
"""
import doctest
[Link]() #
unittest doctest :
import unittest
class TestStatisticalFunctions([Link]):
def test_average(self):
[Link](average([20, 30, 70]), 40.0)
[Link](round(average([1, 5, 7]), 1), 4.3)
with [Link](ZeroDivisionError):
average([])
with [Link](TypeError):
average(20, 30, 70)
[Link]() #
10.12
Python :
• [Link] [Link]
XML
• email MIME RFC 2822
smtplib poplib
• json csv
XML [Link]
[Link] [Link] Python
10.12. 83
Python Tutorial, 3.14.0rc3
84 Chapter 10.
CHAPTER 11
11.1
reprlib repr() :
pprint
:
textwrap :
85
Python Tutorial, 3.14.0rc3
11.2
string Template
$ Python
$$ $:
substitute() KeyError
safe_substitute()
Template
:
>>> t = BatchRename(fmt)
>>> date = [Link]('%d%b%y')
>>> for i, filename in enumerate(photofiles):
... base, ext = [Link](filename)
... newname = [Link](d=date, n=i, f=ext)
... print('{0} --> {1}'.format(filename, newname))
86 Chapter 11.
Python Tutorial, 3.14.0rc3
( )
img_1076.jpg --> Ashley_1.jpg
img_1077.jpg --> Ashley_2.jpg
XML
HTML
11.3
struct pack() unpack()
zipfile ZIP Pack "H" "I"
"<" :
import struct
start = 0
for i in range(3): # 3
start += 14
fields = [Link]('<IIIHH', data[start:start+16])
crc32, comp_size, uncomp_size, filenamesize, extra_size = fields
start += 16
filename = data[start:start+filenamesize]
start += filenamesize
extra = data[start:start+extra_size]
print(filename, hex(crc32), comp_size, uncomp_size)
11.4
I/O
threading :
import threading, zipfile
class AsyncZip([Link]):
def __init__(self, infile, outfile):
[Link].__init__(self)
[Link] = infile
[Link] = outfile
def run(self):
f = [Link]([Link], 'w', zipfile.ZIP_DEFLATED)
[Link]([Link])
[Link]()
print('Finished background zip of:', [Link])
[Link]() #
print('Main program waited until background was done.')
11.3. 87
Python Tutorial, 3.14.0rc3
threading
queue
Queue
11.5
logging
[Link]
import logging
[Link]('Debugging information')
[Link]('Informational message')
[Link]('Warning:config file %s not found', '[Link]')
[Link]('Error occurred')
[Link]('Critical error -- shutting down')
informational debugging
HTTP
DEBUG INFO WARNING ERROR CRITICAL
Python
11.6
Python garbage collection
weakref
88 Chapter 11.
Python Tutorial, 3.14.0rc3
( )
d['primary'] # entry was automatically removed
File "C:/python314/lib/[Link]", line 46, in __getitem__
o = [Link][key]()
KeyError: 'primary'
11.7
array array
( "H") Python int
16 :
collections deque
:
unsearched = deque([starting_node])
def breadth_first_search(unsearched):
node = [Link]()
for m in gen_moves(node):
if is_goal(m):
return m
[Link](m)
bisect :
heapq
:
11.7. 89
Python Tutorial, 3.14.0rc3
11.8
decimal Decimal float
•
•
•
•
•
70 5
:
Decimal Decimal
Decimal :
decimal :
>>> getcontext().prec = 36
>>> Decimal(1) / Decimal(7)
Decimal('0.142857142857142857142857142857142857')
90 Chapter 11.
CHAPTER 12
12.1
Python
Python A 1.0
B 2.0 1.0 2.0
virtual environment Python
A
1.0 B 2.0
B 3.0 A
12.2
venv venv Python --version
python3.12 3.12
venv :
tutorial-env Python
.venv
.env
Windows :
tutorial-env\Scripts\activate
Unix MacOS :
91
Python Tutorial, 3.14.0rc3
source tutorial-env/bin/activate
python
Python
$ source ~/envs/tutorial-env/bin/activate
(tutorial-env) $ python
Python 3.5.1 (default, May 6 2016, 10:59:36)
...
>>> import sys
>>> [Link]
['', '/usr/local/lib/[Link]', ...,
'~/envs/tutorial-env/lib/python3.5/site-packages']
>>>
deactivate
12.3 pip
pip pip Python Package Index
web Python Package Index
pip : ”install”, ”uninstall”, ”freeze” installing-index pip
==
pip
python -m pip install --upgrade
:
92 Chapter 12.
Python Tutorial, 3.14.0rc3
[Link]
install -r
12.3. pip 93
Python Tutorial, 3.14.0rc3
94 Chapter 12.
CHAPTER 13
Python - Python
Python
• library-index:
• installing-index Python
• reference-index: Python
Python
• [Link] Python Python
• [Link] Python
• [Link] The Python Package Index Cheese Shop1 Python
Python [Link]
python-list@[Link]
[Link]
FAQ
95
Python Tutorial, 3.14.0rc3
96 Chapter 13.
CHAPTER 14
14.1 Tab
Tab
Python string.a
'.' __getattr__()
.python_history
14.2
INDENT
IPython tab
bpython
97
Python Tutorial, 3.14.0rc3
98 Chapter 14.
CHAPTER 15
2( ) 0.625 6/10 +
2/100 + 5/1000 0.101 1/2 + 0/4 + 1/8
10 2
1/3
0.3
0.33
0.333
1/3 1/3
2 0.1 2
2 1/10
0.0001100110011001100110011001100110011001100110011...
8 53 2 1/10
3602879701896397 / 2 ** 55 1/10 1/10
Python
Python 0.1
:
>>> 0.1
0.1000000000000000055511151231257827021181583404541015625
Python :
99
Python Tutorial, 3.14.0rc3
>>> 1 / 10
0.1
1/10 1/10
0.1 0.
10000000000000001 0.1000000000000000055511151231257827021181583404541015625
3602879701896397 / 2 ** 55
eval(repr(x)) == x
Python repr() 17 0.
10000000000000001 Python 3.1 Python
0.1
Python
>>> repr([Link])
'3.141592653589793'
[Link]()
:
round()
”0.1” ” ”
Examples of Floating Point Problems
The Perils of Floating Point
Python
2**53
1
str()
formatstrings [Link]()
decimal
fractions
1/3
NumPy SciPy
<[Link]
Python
float.as_integer_ratio() :
>>> x = 3.14159
>>> x.as_integer_ratio()
(3537115888337719, 1125899906842624)
[Link]() 16
:
>>> [Link]()
'0x1.921f9f01b866ep+1'
>>> x == [Link]('0x1.921f9f01b866ep+1')
True
Python
Java C99 .
sum()
>>> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0
False
>>> sum([0.1] * 10) == 1.0
True
[Link]() sum()
101
Python Tutorial, 3.14.0rc3
( )
...
>>> total #
-0.0051575902860057365
15.1
”0.1”
2
Python Perl C C++ Java Fortran
1 / 10 ~= J / (2**N)
J ~= 2**N / 10
56 J 53 N J :
10 :
>>> q+1
7205759403792794
7205759403792794 / 2 ** 56
3602879701896397 / 2 ** 55
1/10
1/10 1/10
” ” 1/10: IEEE 754
:
>>> 0.1 * 2 ** 55
3602879701896397.0
10**55 55 :
>>> 3602879701896397 * 10 ** 55 // 2 ** 55
1000000000000000055511151231257827021181583404541015625
0.1000000000000000055511151231257827021181583404541015625
Python 17
:
fractions decimal :
>>> Fraction.from_float(0.1)
Fraction(3602879701896397, 36028797018963968)
>>> (0.1).as_integer_ratio()
(3602879701896397, 36028797018963968)
>>> Decimal.from_float(0.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')
15.1. 103
Python Tutorial, 3.14.0rc3
16.1
REPL
Windows curses Unix Python 3.13
shell using-on-controlling-color
F1 pydoc F2 »>
... F3 F3
shell PYTHON_BASIC_REPL
16.1.1
try except
1
Control-C Delete
KeyboardInterrupt try
16.1.2 Python
BSD Unix Python shell
#!/usr/bin/env python3
PATH #!
Unix '\n' Windows '\r\n'
'#' Python
chmod
1 GNU Readline
105
Python Tutorial, 3.14.0rc3
$ chmod +x [Link]
16.1.3
Python
PYTHONSTARTUP
Unix shell .profile
Python /dev/tty
Python
sys.ps1
sys.ps2
if
[Link]('.[Link]'): exec(open('.[Link]').read())
import os
filename = [Link]('PYTHONSTARTUP')
if filename and [Link](filename):
with open(filename) as fobj:
startup_file = [Link]()
exec(startup_file)
16.1.4
Python : sitecustomize usercustomize
site-packages Python :
[Link]
Python -s
>>>
interactive shell Python
...
•
abstract base class --
ABC duck-typing
hasattr() ABC
isinstance() issubclass() abc
Python ABC [Link] numbers
io [Link] abc
ABC
annotate function --
__annotate__
annotation --
annotationlib.get_annotations()
variable annotation, function annotation, PEP 484, PEP 526 PEP 649
annotations-howto
argument --
function method
• : name= **
3 5 complex() :
complex(real=3, imag=5)
complex(**{'real': 3, 'imag': 5})
107
Python Tutorial, 3.14.0rc3
• : /
* iterable 3 5 :
complex(3, 5)
complex(*(3, 5))
calls
yield try
__anext__()
PEP 492 PEP 525
asynchronous iterable --
async for __aiter__() asynchronous
iterator PEP 492
asynchronous iterator --
__aiter__() __anext__() __anext__() awaitable
async for __anext__()
StopAsyncIteration PEP 492
attached thread state --
OS thread state
thread state OS Python C API
C API
C API
C
Python GIL
Python
attribute --
o a
o.a
identifiers
setattr() getattr()
awaitable --
await coroutine __await__()
PEP 492
108 Appendix A.
Python Tutorial, 3.14.0rc3
BDFL
Guido van Rossum Python
binary file --
file object ('rb', 'wb' 'rb+')
[Link] [Link] [Link] [Link]
bytecode --
Python CPython Python
.pyc
” ” virtual machine Python
Python
dis
callable --
( argument) :
callback --
class --
class variable --
( )
closure variable --
nested scope free variable
nonlocal
inner x print x :
def outer():
x = 0
def inner():
nonlocal x
x += 1
print(x)
return inner
109
Python Tutorial, 3.14.0rc3
codeobject.co_freevars
free variable
complex number --
-1
i j Python
j 3+1j math
cmath
context --
contiguous --
C Fortran C Fortran
C-
Fortran
coroutine --
cyclic isolate --
decorator --
@wrapper
classmethod() staticmethod()
110 Appendix A.
Python Tutorial, 3.14.0rc3
def f(arg):
...
f = staticmethod(f)
@staticmethod
def f(arg):
...
descriptor --
__get__(), __set__() __delete__()
a.b
a b b
Python
descriptors
dictionary --
__hash__() __eq__()
Perl hash
dictionary comprehension --
results = {n: n **
2 for n in range(10)} n n ** 2 comprehensions
dictionary view --
[Link](), [Link]() [Link]()
list(dictview) dict-views
docstring --
__doc__
duck-typing --
type() isinstance()
( ) hasattr() EAFP
dunder
”double underscore” special method __init__
”dunder init”
EAFP
Python
try except
LBYL C
evaluate function --
type
expression --
statement while
111
Python Tutorial, 3.14.0rc3
extension module --
C C++ Python C API
f-string -- f-
f-strings -- f-
f F ”f- ”
PEP 498
file object --
API read() write()
/
: ,
io open()
file-like object --
file object
filesystem encoding and error handler --
Python Unicode
128
API UnicodeError
[Link]() [Link]()
locale encoding
finder --
loader
: sys.meta_path
sys.path_hooks
finders-and-loaders importlib
floor division --
// 11 // 4
2 2.75 (-11) // 4 -3
-2.75 PEP 238
free threading --
Python global
interpreter lock Python PEP 703
free variable --
112 Appendix A.
Python Tutorial, 3.14.0rc3
function
variable annotation PEP 484 annotations-howto
__future__
future , from __future__ import <feature> Python
__future__ feature
garbage collection --
Python
gc
generator --
generator iterator yield
for- next()
generator iterator --
generator
yield try
generator expression --
iterator expression for
if :
generic function --
GIL
global interpreter lock
global interpreter lock --
CPython Python bytecode
dict CPython
113
Python Tutorial, 3.14.0rc3
Python
frozenset
id()
IDLE
Python idle Python
immortal --
PEP 683 CPython
reference count
True None CPython
sys._is_immortal() C API PyUnstable_IsImmortal()
immutable --
import path --
path based finder
[Link] __path__
importing --
Python Python
importer --
finder loader
interactive --
Python
python
help(x)
interpreted --
Python
/ interactive
interpreter shutdown --
Python
__main__
iterable --
list, str tuple
114 Appendix A.
Python Tutorial, 3.14.0rc3
typeiter
CPython __iter__() CPython
key function --
[Link]()
Python min(),
max(), sorted(), [Link](), [Link](), [Link](), [Link]()
[Link]()
[Link]()
lambda lambda r: (r[0], r[2]) operator.
attrgetter(), [Link]() [Link]()
keyword argument --
argument
lambda
expression lambda
lambda [parameters]: expression
LBYL
EAFP if
LBYL
if key in mapping: return mapping[key] mapping
key EAFP
lexical analyzer --
token
list --
Python sequence
O(1)
list comprehension --
result = ['{:#04x}'.
format(x) for x in range(256) if x % 2 == 0] 0 255
0x.. if range(256)
115
Python Tutorial, 3.14.0rc3
loader --
exec_module() create_module() Loader
finder
• finders-and-loaders
• [Link]
• PEP 302
locale encoding --
Unix LC_CTYPE [Link](locale.
LC_CTYPE, new_locale)
[Link]()
filesystem encoding and error handler
magic method --
special method
mapping --
[Link] [Link].
MutableMapping dict, collections.
defaultdict, [Link] [Link]
meta path finder --
sys.meta_path finder path entry finders
[Link]
metaclass --
Python
metaclasses
method --
module-specs
MRO
method resolution order
mutable --
id() immutable
116 Appendix A.
Python Tutorial, 3.14.0rc3
named tuple --
[Link]() [Link]()
sys.float_info:
>>> sys.float_info[1] #
1024
>>> sys.float_info.max_exp #
1024
>>> isinstance(sys.float_info, tuple) #
True
tuple
typing.
NamedTuple [Link]()
namespace --
[Link] [Link]()
namespace package --
package regular
package __init__.py
regular package
PEP 420 reference-namespace-package
module
nested scope --
nonlocal
new-style class --
Python
Python __slots__ __getattribute__()
object --
object new-style class
optimized scope --
package --
Python module __path__
Python
regular package namespace package
parameter --
function argument
117
Python Tutorial, 3.14.0rc3
• positional-or-keyword
foo bar:
• positional-only
/ posonly1 posonly2:
• keyword-only
*
kw_only1 kw_only2:
• var-positional
* args:
• var-keyword
** kwargs
[Link]
path entry hook --
path entry sys.path_hooks
path entry finder
path based finder --
import path
path-like object --
str bytes
[Link] [Link] os.
fspath() str bytes [Link]() [Link]()
str bytes PEP 519
PEP
Python PEP Python
Python PEP
PEP Python
PEP
PEP 1
portion --
zip PEP
420
118 Appendix A.
Python Tutorial, 3.14.0rc3
positional argument --
argument
provisional API -- API
API
-- API
API
PEP
411
provisional package --
provisional API
Python 3000
Python 3.x 3
Py3k
Pythonic
Python
Python for
Python :
for i in range(len(food)):
print(food[i])
Pythonic :
qualified name --
PEP 3155 :
>>> class C:
... class D:
... def meth(self):
... pass
...
>>> C.__qualname__
'C'
>>> C.D.__qualname__
'C.D'
>>> [Link].__qualname__
'[Link]'
[Link]:
reference count --
immortal
Python
CPython [Link]()
119
Python Tutorial, 3.14.0rc3
CPython Python
regular package --
package __init__.py
namespace package
REPL
- - read-eval-print loop interactive shell
__slots__
sequence --
iterable __getitem__()
__len__() list, str, tuple bytes
dict __getitem__() __len__()
hashable
[Link] __getitem__()
__len__() count(), index(), __contains__() __reversed__()
register()
set comprehension --
results = {c for c
in 'abracadabra' if c not in 'abc'} {'r', 'd'} comprehensions
single dispatch --
generic function
slice --
sequence []
variable_name[1:3:5] slice
soft deprecated --
API API
API
PEP 387: Soft Deprecation
special method --
Python
specialnames
standard library --
Python ,
library-index
sys.stdlib_module_names
statement --
expression
if while for
120 Appendix A.
Python Tutorial, 3.14.0rc3
stdlib --
standard library
strong reference --
Python C API
Py_INCREF() Py_DECREF()
Py_NewRef()
Py_DECREF()
borrowed reference
t-string -- t-
t-strings -- t-
t T ”t- ”
text encoding --
Python Unicode U+0000--U+10FFFF
” ”
text file --
str file object
text encoding 'r' 'w' [Link]
[Link] [Link]
binary file
thread state --
CPython OS
OS
OS
token --
( )
triple-quoted string --
” ’
type --
Python
__class__ type(obj)
type alias --
121
Python Tutorial, 3.14.0rc3
def remove_gray_shades(
colors: list[tuple[int, int, int]]) -> list[tuple[int, int, int]]:
pass
variable annotation --
annotation
:
class C:
field: 'annotation'
int :
count: int = 0
annassign
function annotation, PEP 484 PEP 526 annotations-howto
virtual environment --
Python Python
Python
venv
virtual machine --
Python bytecode
:=
Zen of Python -- Python
Python
”import this”
122 Appendix A.
APPENDIX B
Python
reporting-bugs
B.1 Python
Python Python Python Python Misc/ACKS
Python Python
123
Python Tutorial, 3.14.0rc3
124 Appendix B.
APPENDIX C
C.1
Python 1990 Guido van Rossum Stichting Mathematisch Centrum (CWI https:
//[Link]) ABC Guido Python
1995 Guido Reston Corporation for National Research Initiatives (CNRI https:
//[Link]) Python
2000 5 Guido Python [Link] BeOpen PythonLabs
10 PythonLabs Digital Creations Zope Corporation 2001 Python Software
Foundation (PSF [Link] Python
Zope Corporation PSF
Python ( [Link]
Python GPL
GPL ? (1)
0.9.0 1.2 n/a 1991-1995 CWI
1.3 1.5.2 1.2 1995-1999 CNRI
1.6 1.5.2 2000 CNRI
2.0 1.6 2000 [Link]
1.6.1 1.6 2001 CNRI (2)
2.1 2.0+1.6.1 2001 PSF
2.0.1 2.0+1.6.1 2001 PSF
2.1.1 2.1+2.0.1 2001 PSF
2.1.2 2.1.1 2002 PSF
2.1.3 2.1.2 2002 PSF
2.2 2.1.1 2001 PSF
125
Python Tutorial, 3.14.0rc3
GPL
(2) Richard Stallman 1.6.1 GPL
CNRI Stallman CNRI 1.6.1 GPL ” ”
Guido
C.2 Python
Python Python Software Foundation License Version 2
Python 3.8.6 PSF License Version 2 Zero-Clause BSD
license
Python
2. Subject to the terms and conditions of this License Agreement, PSF hereby
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
analyze, test, perform and/or display publicly, prepare derivative works,
distribute, and otherwise use Python alone or in any derivative
version, provided, however, that PSF's License Agreement and PSF's notice of
copyright, i.e., "Copyright © 2001 Python Software Foundation; All Rights
Reserved" are retained in Python alone or in any derivative version
prepared by Licensee.
126 Appendix C.
Python Tutorial, 3.14.0rc3
2. Subject to the terms and conditions of this BeOpen Python License Agreement,
BeOpen hereby grants Licensee a non-exclusive, royalty-free, world-wide license
to reproduce, analyze, test, perform and/or display publicly, prepare derivative
works, distribute, and otherwise use the Software alone or in any derivative
version, provided, however, that the BeOpen Python License is retained in the
Software, alone or in any derivative version prepared by Licensee.
4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE SOFTWARE FOR
ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF USING,
MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY DERIVATIVE THEREOF, EVEN IF
ADVISED OF THE POSSIBILITY THEREOF.
2. Subject to the terms and conditions of this License Agreement, CNRI hereby
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
analyze, test, perform and/or display publicly, prepare derivative works,
distribute, and otherwise use Python 1.6.1 alone or in any derivative version,
provided, however, that CNRI's License Agreement and CNRI's notice of copyright,
i.e., "Copyright © 1995-2001 Corporation for National Research Initiatives; All
Rights Reserved" are retained in Python 1.6.1 alone or in any derivative version
prepared by Licensee. Alternately, in lieu of CNRI's License Agreement,
Licensee may substitute the following text (omitting the quotes): "Python 1.6.1
is made available subject to the terms and conditions in CNRI's License
Agreement. This Agreement together with Python 1.6.1 may be located on the
( )
( )
internet using the following unique, persistent identifier (known as a handle):
1895.22/1013. This Agreement may also be obtained from a proxy server on the
internet using the following URL: [Link]
4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS" basis. CNRI
MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
BUT NOT LIMITATION, CNRI MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY
OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
PYTHON 1.6.1 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 1.6.1 FOR
ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF
MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1, OR ANY DERIVATIVE
THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided that
the above copyright notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting documentation, and that
the name of Stichting Mathematisch Centrum or CWI not be used in advertising or
publicity pertaining to distribution of the software without specific, written
prior permission.
128 Appendix C.
Python Tutorial, 3.14.0rc3
( )
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
C.3
Python
C.3. 129
Python Tutorial, 3.14.0rc3
( )
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
C.3.2
socket getaddrinfo() getnameinfo() WIDE : [Link]
Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
All rights reserved.
THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
C.3.3
[Link] [Link] :
Copyright 1996 by Sam Rushing
130 Appendix C.
Python Tutorial, 3.14.0rc3
( )
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
C.3.4 Cookie
[Link] :
C.3.5
trace :
Permission to use, copy, modify, and distribute this Python software and
its associated documentation for any purpose without fee is hereby
granted, provided that the above copyright notice appears in all copies,
and that both that copyright notice and this permission notice appear in
supporting documentation, and that the name of neither Automatrix,
( )
C.3. 131
Python Tutorial, 3.14.0rc3
( )
Bioreason or Mojam Media be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.
C.3.7 XML
[Link] :
SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR
BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
( )
132 Appendix C.
Python Tutorial, 3.14.0rc3
( )
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE.
C.3.8 test_epoll
test.test_epoll :
Copyright (c) 2000 Doug White, 2006 James Knight, 2007 Christian Heimes
All rights reserved.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
C.3. 133
Python Tutorial, 3.14.0rc3
C.3.10 SipHash24
Python/pyhash.c Marek Majkowski’ Dan Bernstein SipHash24
:
<MIT License>
Copyright (c) 2013 Marek Majkowski <marek@[Link]>
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
</MIT License>
Original location:
[Link]
C.3.12 OpenSSL
hashlib, posix ssl OpenSSL Python Windows
macOS OpenSSL OpenSSL
OpenSSL 3.0 Apache License v2:
Apache License
Version 2.0, January 2004
[Link]
( )
134 Appendix C.
Python Tutorial, 3.14.0rc3
( )
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
C.3. 135
Python Tutorial, 3.14.0rc3
( )
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
( )
136 Appendix C.
Python Tutorial, 3.14.0rc3
( )
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
C.3.13 expat
pyexpat expat --with-system-expat:
Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
and Clark Cooper
C.3. 137
Python Tutorial, 3.14.0rc3
( )
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
C.3.14 libffi
ctypes _ctypes C libffi
--with-system-libffi:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
C.3.15 zlib
zlib zlib zlib :
Copyright (C) 1995-2011 Jean-loup Gailly and Mark Adler
1. The origin of this software must not be misrepresented; you must not
( )
138 Appendix C.
Python Tutorial, 3.14.0rc3
( )
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
C.3.16 cfuhash
tracemalloc cfuhash :
Copyright (c) 2005 Don Owens
All rights reserved.
C.3.17 libmpdec
decimal _decimal C libmpdec
--with-system-libmpdec:
C.3. 139
Python Tutorial, 3.14.0rc3
( )
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
C.3.19 mimalloc
MIT :
Copyright (c) 2018-2021 Microsoft Corporation, Daan Leijen
140 Appendix C.
Python Tutorial, 3.14.0rc3
( )
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
C.3.20 asyncio
asyncio uvloop 0.16 MIT :
Copyright (c) 2015-2021 MagicStack Inc. [Link]
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
( )
C.3. 141
Python Tutorial, 3.14.0rc3
( )
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
C.3.22 Zstandard
Modules/_zstd Lib/compression/zstd Zstandard pyzstd
Ma Lin pyzstd 3 BSD :
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
142 Appendix C.
APPENDIX D
Python
© 2001 Python
© 2000 [Link]
© 1995-2000 Corporation for National Research Initiatives
© 1991-1995 Stichting Mathematisch Centrum
143
Python Tutorial, 3.14.0rc3
144 Appendix D.
asynchronous iterable -- ,
..., 107 108
ellipsis literal -- , 107 asynchronous iterator -- , 108
, 18 attached thread state -- , 108
# (hash) attribute -- , 108
,7 awaitable -- , 108
*( )
, 27 B
** BDFL, 109
, 27 binary file -- , 109
:( ) borrowed reference -- , 109
, 28 builtins
-> module, 45
, 28 bytecode -- , 109
>>>, 107 bytes-like object -- , 109
__all__, 47
__future__, 113 C
__slots__, 120 C , 110
callable -- , 109
method -- , 120 callback -- , 109
class -- , 109
PATH, 43, 105 class variable -- , 109
PYTHON_BASIC_REPL, 105 closure variable -- , 109
PYTHON_GIL, 113 complex number -- , 110
PYTHONPATH, 43, 44 context -- , 110
PYTHONSTARTUP, 106 context management protocol --
, 110
style, 28 context manager -- , 110
context variable -- , 110
method -- , 116 contiguous -- , 110
coroutine -- , 110
A coroutine function -- , 110
abstract base class -- , 107 CPython, 110
annotate function -- , 107 current context -- , 110
annotation -- , 107 cyclic isolate -- , 110
annotations
function -- , 28 D
argument -- , 107 decorator -- , 110
asynchronous context manager -- descriptor -- , 111
, 108 dictionary -- , 111
asynchronous generator -- , 108 dictionary comprehension -- , 111
asynchronous generator iterator -- dictionary view -- , 111
, 108 docstring -- , 111
145
Python Tutorial, 3.14.0rc3
146
Python Tutorial, 3.14.0rc3
open R
, 53 reference count -- , 119
optimized scope -- , 117 regular package -- , 120
REPL, 120
P RFC
package -- , 117 RFC 2822, 83
parameter -- , 117
PATH, 43, 105 S
path sequence -- , 120
module , 43 set comprehension -- , 120
path based finder -- , 118 single dispatch -- , 120
path entry -- , 118 sitecustomize, 106
path entry finder -- , 118 slice -- , 120
path entry hook -- , 118 soft deprecated -- , 120
path-like object -- , 118 special method -- , 120
PEP, 118 standard library -- , 120
portion -- , 118 statement --
positional argument -- , 119 for, 15
provisional API -- API, 119 statement -- , 120
provisional package -- , 119 static type checker -- , 120
Python 3000, 119 stdlib -- , 121
Python PEP 1, 118 string
Python PEP 8, 29 , 50
Python PEP 238, 112 , 50
Python PEP 278, 122 strong reference -- , 121
Python PEP 302, 116 style
Python PEP 343, 110 , 28
Python PEP 362, 108, 118 sys
Python PEP 411, 119 module, 44
Python PEP 420, 117, 118
Python PEP 443, 113 T
Python PEP 483, 113 t-string -- t- , 121
Python PEP 484, 28, 107, 113, 122 t-strings -- t- , 121
Python PEP 492, 108, 110 text encoding -- , 121
Python PEP 498, 112 text file -- , 121
Python PEP 519, 118 thread state -- , 121
Python PEP 525, 108 token -- , 121
Python PEP 526, 107, 122 triple-quoted string -- , 121
Python PEP 585, 113 type -- , 121
Python PEP 636, 21 type alias -- , 121
Python PEP 649, 107 type hint -- , 122
Python PEP 683, 114
Python PEP 703, 112, 113 U
Python PEP 765, 62
universal newlines -- , 122
Python PEP 3107, 28
usercustomize, 106
Python PEP 3116, 122
Python PEP 3147, 44 V
Python PEP 3155, 119
variable annotation -- , 122
PYTHON_BASIC_REPL, 105
PYTHON_GIL, 113
help, 79
Pythonic, 119
open, 53
PYTHONPATH, 43, 44
virtual environment -- , 122
PYTHONSTARTUP, 106
virtual machine -- , 122
Q , 21, 28
qualified name -- , 119 W
147
Python Tutorial, 3.14.0rc3
name, 74
, 50
path, module, 43
object -- , 53
, 21, 28
, 50
, 122
Z
Zen of Python -- Python , 122
148