Return to Python Distilled, Python books
Python: Python Variables, Python Data Types, Python Control Structures, Python Loops, Python Functions, Python Modules, Python Packages, Python File Handling, Python Errors and Exceptions, Python Classes and Objects, Python Inheritance, Python Polymorphism, Python Encapsulation, Python Abstraction, Python Lists, Python Dictionaries, Python Tuples, Python Sets, Python String Manipulation, Python Regular Expressions, Python Comprehensions, Python Lambda Functions, Python Map, Filter, and Reduce, Python Decorators, Python Generators, Python Context Managers, Python Concurrency with Threads, Python Asynchronous Programming, Python Multiprocessing, Python Networking, Python Database Interaction, Python Debugging, Python Testing and Unit Testing, Python Virtual Environments, Python Package Management, Python Data Analysis, Python Data Visualization, Python Web Scraping, Python Web Development with Flask/Django, Python API Interaction, Python GUI Programming, Python Game Development, Python Security and Cryptography, Python Blockchain Programming, Python Machine Learning, Python Deep Learning, Python Natural Language Processing, Python Computer Vision, Python Robotics, Python Scientific Computing, Python Data Engineering, Python Cloud Computing, Python DevOps Tools, Python Performance Optimization, Python Design Patterns, Python Type Hints, Python Version Control with Git, Python Documentation, Python Internationalization and Localization, Python Accessibility, Python Configurations and Environments, Python Continuous Integration/Continuous Deployment, Python Algorithm Design, Python Problem Solving, Python Code Readability, Python Software Architecture, Python Refactoring, Python Integration with Other Languages, Python Microservices Architecture, Python Serverless Computing, Python Big Data Analysis, Python Internet of Things (IoT), Python Geospatial Analysis, Python Quantum Computing, Python Bioinformatics, Python Ethical Hacking, Python Artificial Intelligence, Python Augmented Reality and Virtual Reality, Python Blockchain Applications, Python Chatbots, Python Voice Assistants, Python Edge Computing, Python Graph Algorithms, Python Social Network Analysis, Python Time Series Analysis, Python Image Processing, Python Audio Processing, Python Video Processing, Python 3D Programming, Python Parallel Computing, Python Event-Driven Programming, Python Reactive Programming.
Variables, Data Types, Control Structures, Loops, Functions, Modules, Packages, File Handling, Errors and Exceptions, Classes and Objects, Inheritance, Polymorphism, Encapsulation, Abstraction, Lists, Dictionaries, Tuples, Sets, String Manipulation, Regular Expressions, Comprehensions, Lambda Functions, Map, Filter, and Reduce, Decorators, Generators, Context Managers, Concurrency with Threads, Asynchronous Programming, Multiprocessing, Networking, Database Interaction, Debugging, Testing and Unit Testing, Virtual Environments, Package Management, Data Analysis, Data Visualization, Web Scraping, Web Development with Flask/Django, API Interaction, GUI Programming, Game Development, Security and Cryptography, Blockchain Programming, Machine Learning, Deep Learning, Natural Language Processing, Computer Vision, Robotics, Scientific Computing, Data Engineering, Cloud Computing, DevOps Tools, Performance Optimization, Design Patterns, Type Hints, Version Control with Git, Documentation, Internationalization and Localization, Accessibility, Configurations and Environments, Continuous Integration/Continuous Deployment, Algorithm Design, Problem Solving, Code Readability, Software Architecture, Refactoring, Integration with Other Languages, Microservices Architecture, Serverless Computing, Big Data Analysis, Internet of Things (IoT), Geospatial Analysis, Quantum Computing, Bioinformatics, Ethical Hacking, Artificial Intelligence, Augmented Reality and Virtual Reality, Blockchain Applications, Chatbots, Voice Assistants, Edge Computing, Graph Algorithms, Social Network Analysis, Time Series Analysis, Image Processing, Audio Processing, Video Processing, 3D Programming, Parallel Computing, Event-Driven Programming, Reactive Programming.
Python Glossary, Python Fundamentals, Python Inventor: Python Language Designer: Guido van Rossum on 20 February 1991; PEPs, Python Scripting, Python Keywords, Python Built-In Data Types, Python Data Structures - Python Algorithms, Python Syntax, Python OOP - Python Design Patterns, Python Module Index, pymotw.com, Python Package Manager (pip-PyPI), Python Virtualization (Conda, Miniconda, Virtualenv, Pipenv, Poetry), Python Interpreter, CPython, Python REPL, Python IDEs (PyCharm, Jupyter Notebook), Python Development Tools, Python Linter, Pythonista-Python User, Python Uses, List of Python Software, Python Popularity, Python Compiler, Python Transpiler, Python DevOps - Python SRE, Python Data Science - Python DataOps, Python Machine Learning, Python Deep Learning, Functional Python, Python Concurrency - Python GIL - Python Async (Asyncio), Python Standard Library, Python Testing (Pytest), Python Libraries (Flask), Python Frameworks (Django), Python History, Python Bibliography, Manning Python Series, Python Official Glossary - Python Glossary, Python Topics, Python Courses, Python Research, Python GitHub, Written in Python, Python Awesome List, Python Versions. (navbar_python - see also navbar_python_libaries, navbar_python_standard_library, navbar_python_virtual_environments, navbar_numpy, navbar_datascience)
ADD the ddg> and the python> Python Docs search feature to each item below.
Fair Use Source: B094CMKN2J, PyDis
Index
banker’s rounding, 5
base classes, 160
abstract, 185–188
invoking menthods of, 313
linking to, 207
__slots__ variable and, 210
tuple of, 222
used for type hinting, 184–185
base64 module, 274
BaseException exception, 67–68, 314
__bases__ attribute, 207, 222
bash shell, 1
bin() function, 37, 297
binary data structures, 288
binary integers, 6
binascii module, 274
bit manipulation, 6
bit_length() method, 305
bitwise operators, 6, 40, 57
blocking, 269–273
BlockingIOError exception, 270, 316
bool class, 297
bool type, 298
__bool__() method, 93–95
Boolean values, 6–7, 38, 43–44, 297
bound methods, 158, 183
break statement, 8, 12, 62–63, 141
breakpoint() function, 298
BrokenPipeError exception, 316
BSD socket interface, 286
BufferedXXX classes, 260
BufferError exception, 315
byte arrays, 247, 266, 298–300
bytearray type, 247, 298
bytes, 247–248
comparing, 43
converting to text, 274
formatting, 253–254
operations on, 298–300
serializing objects into, 268
bytes module, 274
bytes type, 247–248, 298
__bytes__() method, 94–95
BytesIO class, 280
C programming language, 281, 286, 288
__call__() method, 98, 219
callable() function, 301
callback functions, 114, 116
passing arguments to, 118–121
returning results from, 121–123
CallbackError exception, 122
capitalize() method, 298, 310
casefold() method, 310
category() function, 295
__cause__ attribute, 65, 71–73, 315
__ceil__() method, 91
center() method, 298, 310
cgi module, 275
characters
end of file (EOF), 2, 68, 315
line-feed, see newline characters
ordinal values of, 307
check_output() function, 288–289
child classes, see subclasses
ChildProcessError exception, 316
chr() function, 301
circular dependency, 82
class methods, 89, 170–172, 222, 301
class statement, 27, 154–155, 215–218
base-class names in, 160
class variables, 169–172, 222
mutating, 112
__class__ attribute, 206, 223
classes, 80, 153–223
adding methods to, 28
body of, 215
built-in, 313
creating, 160, 215–218
duplicating definitions of, 221
extending, 160
inspecting, 318
internal variables in, 27
linking instances to, 206, 223
membership testing for, 183
names of, 222
namespace of, 215, 218
static methods in, 173
type-checking, 162
uniformity of, 183
user-defined, 179, 206–207
with a single method, 166
classmethod object, 125
@classmethod decorator, 125, 170–171, 183, 197, 213, 301
classobj type, 305
cleanup, 66, 141
clear() method, 300, 302, 309
click module, 255
close() method, 12, 147, 202, 258, 262, 315
closed attribute, 263
__closure__ attribute, 129
closures, 116–117, 129
cls object, 125, 171, 220, 222
code, see also programs
generating, 222, 233
Pythonic, 99–100, 160, 176
readability of, 103, 223
testing, 223
code-checking tools, 87, 107
__code__ attribute, 129–130
collect() function, 82
collections module, 20, 81, 168, 240, 318
comma-separated values (CSVs), 276
command-line options, 15, 33, 254–255, 317, 319
comments, 2
extracting, 55
comparisons, 6, 42, 93
between bytes and text, 248
compile() function, 301
complex() function, 301
__complex__() method, 94–95, 301
compound-interest calculation, 4
compute_usage() function, 282–283
concatenation, 47
of tuples, 16
concurrency, 148, 269, 273, 291–293
conditionals, 4, 7–9, 44–45, 59–60
configparser module, 276
conjugate() method, 303, 305
ConnectionXXXError exceptions, 316
containers, 95–96
__contains__() method, 95–96
context managers, 75–77, 99
asynchronous, 136–137
cleaning up with, 141
__context__ attribute, 65, 72–73, 315
contextlib module, 77, 148
@contextmanager decorator, 148
continue statement, 8, 62–63
control flow
with conditionals, 7–9, 59–60
with exceptions, 64–69, 77
with loops, 60–63
copy() method, 300, 302, 309
copying, of sequences, 47–48
coroutines, 135
generator-based, 146
inspecting, 318
cos() function, 318
count() method, 298, 307, 310, 313
Counter class, 318
cryptographic hash values, 278
csv module, 31, 276
ctime() function, 293
currentframe() function, 132
daemon flag, 291
data encapsulation, 176
data hiding, 178
@dataclass decorator, 134
dataclasses, 196, 233
datetime module, 293, 318
deadlocks, 25, 204
debug variable, 215
debug() function, 133, 281
debugging
breakpoint for, 298
error messages for, 66, 124
exception handling and, 74
in Python development environment, 3
introducing code for, 77–78
logging for, 280
making output for, 162
modules individually, 235
smaller tasks, 145
stack frames and, 133
when using dictionaries, 21
with __dict__ attribute, 211
with repr(), 11
with __repr__(), 28, 196
decode() method, 248, 259, 298, 310
decorators, 104, 124–127, 194–197, 220
deep copies, 83
deepcopy() function, 84
def statement, 22, 27, 101
DEFAULT_BUFFER_SIZE value, 259
defaultdict class, 318
del statement, 19, 50–51, 82–83, 89, 202, 207, 300–302, 307
__del__() method, 89, 201–206
delattr() function, 157, 179, 301
__delattr__() method, 98, 207
delegation, 208–210
__delete__() method, 211
__delitem__() method, 95–96
dependency injection, 165, 176
deque class, 81, 318
descriptors, 211–214, 220, 285
Design Patterns book, 176
detach() method, 261
dict type, 80, 301–302
dict() function, 20, 51, 168
__dict__ attribute, 206–207, 211, 215, 222–223, 242, 302, 313
dictionaries, 18–21
accessing members of, 18
adding unusual items to, 85–87
as literals, 38
assignments on, 83
converting to lists, 20
creating, 18, 20, 53–54
deep vs. shallow copies of, 83
dispatching through, 193
empty, 20, 43
initializing missing items automatically, 318
inserting objects into, 18
iterating over, 21
keys of, 20–21, 294–295
modifying objects of, 18
nested, 19
no ordered comparisons on, 43
number of items in, 306
operations on, 51, 301–302
passed as function parameters, 107
removing elements from, 19, 104
using tuples in, 19
values of, 21
dictionary comprehension, 20, 53–54
dictionary lookups, 176
DictReader class, 277
difference operation, 18, 50, 309
difference() method, 309
difference_update() method, 309
dir() function, 26, 31, 302
__dir__() method, 302
directories, 264
current working, 234
temporary, 289
discard() method, 18, 50, 309
distutils module, 243
division, 5, 303
divmod() function, 5, 40, 303
__divmod__() method, 90
Django library, 279
__doc__ attribute, 106, 129, 222, 242
docopt module, 255
documentation strings, 106, 129, 155, 222, 242
dot operator, see . operator
double-ended queues, 318
duck typing, 167
dump() function, 268
dumps() function, 280
dynamic binding, 167
e, E, in numbers, 37
echo servers, 286
.egg suffix, 234
elif statement, 7–8, 59–60, 193
Ellipsis object, 96
else statement, 7–9, 44–45, 57, 59–60, 63, 66, 193
emails, sending, 285
encode() method, 248, 259, 310
encoding attribute, 13, 259–260, 263
encodings, 248–249, 263
end keyword, 265, 308
endswith() method, 10, 298, 311
__enter__() method, 75, 99, 148
enumerate() function, 61, 303
env command, 256
environment variables, 256
EnvironmentError exception, 314–316
EOF (end of file) character, 2, 68, 315
EOFError exception, 68, 315
epoll() function, 285
__eq__() method, 93–94
errno attribute, 316
errno module, 277–278
errors
handling, 110–111
logging, 66
errors attribute, 259–260, 263
eval() function, 89, 301, 303, 308
Event class, 292
except statement, 24–25, 64–66, 70, 110
narrowness of, 74
Exception exception, 66–69, 314
exceptions, 24–25, 64–75
altering control flow, 67–69
asynchronous, 69
built-in, 67–68, 75, 314–318
catching, 64, 66, 70, 73–74
chained, 70–73, 315
defining new, 69–70, 74
expected vs. unexpected, 72–73
extracting values attached to, 141
handling, 24–25, 73–75, 110–111, 121–122, 277–278
hierarchy of, 67–68, 70
ignoring, 65–66
predefined, 315–318
propagating, 64
raising, 64, 69, 110, 147, 315
standard attributes of, 64–65
traceback messages of, 70, 73
user-defined, 69, 314
wrapping with a function, 54
exec() function, 133–134, 233, 301, 303
__exit__() method, 75, 99, 148
expandtabs() method, 298, 311
expressions, 3, 38–39
evaluating, 43, 303
extend() method, 300, 307
Extensible Markup Language (XML), 295
f-strings, 4, 9, 11, 251–252
False value, 6–7, 38, 43–45, 297–298
fast lookups, 19
fcntl module, 262, 278
fcntl() function, 278
file descriptors, 257, 262
file keyword, 265, 308
file modes, 258, 263
file objects, 258, 262, 307
attributes of, 263
implementing, 279
manipulating, 261
methods supported by, 261
standard, 263
file pointers, 262
__file__ attribute, 36, 242
__file__ variable, 241
FileExistsError exception, 258, 316
FileIO class, 260
filename attribute, 316–317
fileno() method, 262
FileNotFoundError exception, 277, 316
files
converting between binary and text, 261
copying, 284, 319
encoding of, 13, 263
locking, 278
metadata of, 282
names of, 257–258, 263
newline characters in, 260, 263
opening, 12, 256–258
overwritting, 258
parsing, 105
paths to, 281–283
reading, 12–13, 262
removing, 284, 319
state of, 263
temporary, 289
writing to, 262, 268
filter() function, 128, 303
filtering, 127–128
finally statement, 25, 66, 141
find() method, 10, 299, 311
first-class objects, 85–87, 115, 242
flag variables, 63
flask library, 279
float() function, 11, 303, 315
__float__() method, 94–95, 303
FloatingPointError exception, 67, 314–315
floats, 3, 5, 37–38, 303, 315
converting to text, 250–251
precision of, 288
rounding, 5, 308
flock() function, 278
__floor__() method, 91
__floordiv__() method, 90
flush() method, 259, 262
flyweight pattern, 176
for statement, 12–13, 21–22, 45, 60–63, 140, 176
for reading lines in a file, 262
implementing, 97
nested, 144–145
on lists, 52
format() function, 11, 94, 250, 304
format() method, 9, 252–253, 311
__format__() method, 94, 304
format_map() method, 311
from statement, 31, 228–230, 237, 316
from_ prefix, in method names, 172
from_bytes() method, 305
fromhex() method, 274, 303
fromkeys() method, 302
frozenset() function, 304, 309
__fspath__() method, 257
function call operator, 56
functions, 22–24, 101–131, 137
accepting iterables, 47
arguments of
default, 23, 101–102, 115
default values for, 87, 157
evaluated left-to-right, 101
keyword, 103–104
number of, 101–102
order of, 101
positional, 105–106
asynchronous, 135–137, 272, 317
attribute access, 207
attributes of, 129–130
built-in, 297–314
callback, 114, 116, 118–123
comparing, 131
debugging messages in, 124
defining, 22, 101
delayed execution of, 145
documenting, 106, 129, 155
emulating, 98
evaluating, 116
helper, 106
higher-order, 115–118
inspecting, 131–133, 318
invoking, 22, 101, 111
local variables in, 24, 107, 111–113, 149–151
metadata of, 124–125, 130
naming, 106, 129
nested, 113, 116–117, 129
recursive, 114
return values of, 23, 109–110
side effects in, 108
signature of, 130–131
type hints in, 107, 129, 155
wrappers around, 124
functools module, 94
futures, 123
garbage collection, 26, 81–83, 89, 141, 203–204
gc module, 82
__ge__() method, 93
generator expressions, 54–56, 128
GeneratorExit exception, 147, 314–315
generators, 97, 139–152
asynchronous, 317
creating, 54
delegating, 142–144
emitting I/O streams, 265–266
enhanced, 146–151, 266–267
for repeated iterations, 142
inspecting, 318
terminating, 315
get() method, 19, 302
__get__() method, 211–213
get_data() function, 242
getattr() function, 157, 179, 193–194, 304
__getattr__() method, 98, 207–211
__getattribute__() method, 98, 207, 211
__getitem__() method, 95–96, 159–308
getsize() function, 282
__getstate__() method, 268
glob() function, 264
global statement, 112
globals() function, 131, 303–304
__globals__ attribute, 129, 131
globbing, 264
gmtime() function, 293
__gt__() method, 93
hasattr() function, 157, 179, 304
hash() function, 304
__hash__() method, 93–94
hashlib module, 278
help() command, 22
hex() function, 37, 95, 304
hex() method, 274, 299, 303
higher-order functions, 115–118
http package, 279
httpx library, 279, 294
HyperText Markup Language (HTML), 279
Hypertext Transfer Protocol (HTTP), 279, 293–294
__iadd__(), __iand__() methods, 91–92
id() function, 80, 304
identifiers, 38
identity checks, 92
__idivmod__() method, 91–92
if statement, 7–9, 39, 44–45, 52, 57, 59–60, 193
__ifloordiv__(), __ilshift__(), __imatmul__(), __imod__() methods, 91–92
import statement, 15, 30–35, 59, 225–237, 241, 245, 316
inside a function, 228, 231
ImportError exception, 31, 67–68, 226, 237, 316
importlib library, 232
__imul__() method, 91–92
in operator, 19, 45, 50–52, 57, 96, 302
in-place assignment, see assignments, augmented
indent() function, 290
indentation, 4, 316
IndentationError exception, 316
index() method, 299, 307, 311, 313
__index__() method, 94–95
IndexError exception, 48, 49, 67, 314, 316
indexing operator, 13
on dictionaries, 18
on tuples, 16
info() function, 281
inheritance, 28–30, 160–163
breaking code with, 162
from built-in types, 167–169
multiple, 163, 187–192, 211
cooperative, 190–192
propagating metaclasses via, 220
__slots__ variable and, 210
supervised, 197–199
via composition, 164–166
via functions, 166–167
via implementation, 163–164
INI files, 276
__init__() method, 27, 70, 89, 134, 154–155, 161, 181–201, 219–220
__init__.py file, 34–35, 235–237, 239–241
__init_subclass__() method, 197–199, 220–222
input() function, 13, 33, 304, 315
input/output (I/O), 247–296
buffering, 258–260
consuming input, 266–267
error handling, 249, 256, 259, 316
generating output, 265–266
handling, 288, 291
in binary mode, 257–259
in text mode, 258–260
nonblocking, 270
polling channels of, 271, 273, 284
insert() method, 13, 26, 300, 307
inspect module, 318
instances, 79, 154–156
adding attributes to, 161, 206
alternate constructors of, 170–172
caching, 200–201, 204–206
creating, 89, 199
deleting an attribute of, 156
destroying, 89, 201
getting, 156
initializing, 89
linking to classes, 206, 223
setting, 156
state associated with, 206, 223
storing data of, 210–211
int class, 80
int() function, 11, 95, 305
__int__() method, 94–95
integers, 3, 305
as literals, 37
base of, 37
binary, 6
converting
to text, 251
to/from bytes, 305
creating strings from
binary, 37, 297
hexadecimal, 37, 299, 303–304
octal, 37, 307
iterating over, 21
precision of, 316
ranges of, 21–22, 308
testing values of, 303
interfaces, 184–188
interpreter, 1, 3
InterruptedError exception, 316
intersection operation, 18, 50, 309
intersection() method, 309
__invert__() method, 91
io module, 260–261, 279–280
ioctl() function, 278
IOError exception, 316
__ior__(), __ipow__() methods, 91–92
ipython shell, 2
__irshift__() method, 91–92 “is a” relationship, 163
is not operator, 42, 57, 80
is operator, 42, 57, 80, 92
is_integer() method, 303
IsADirectoryError exception, 316
isalnum(), isalpha() methods, 299, 311
isascii() method, 311
isatty() method, 262
isdecimal() method, 311
isdigit() method, 299, 311
isdir() function, 282
isdisjoint() method, 309
isfile() function, 282
isidentifier() method, 311
isinstance() function, 64, 81, 183, 305
islower() method, 299, 311
isnumeric(), isprintable() methods, 311
isspace() method, 299, 311
issubclass() function, 184, 305
issubset(), issuperset() methods, 309
istitle() method, 299, 311
__isub__() method, 91–92
isupper() method, 299, 311
items() method, 21, 51, 302
iter() function, 305
__iter__() method, 97–98, 142, 152, 160, 305
iterations, 21–22, 45–47, 60–62, 97–98, 305
ending, 69
handling, 307, 318
nested, 143
producing values for, 139
repeated, 142
reversed, 308
iterator objects
asynchronous, 136–137
creating, 22, 61
implementing, 98, 152
internal stack of, 146
reversed, 97
itertools module, 318
__itruediv__() method, 91–92
__ixor__() method, 91–92
join() function, 281
join() method, 299, 311
JSON format, 280
json module, 280
KeyboardInterrupt exception, 67, 69, 314, 316
KeyError exception, 67, 314, 316
keys() method, 20, 51, 302
kqueue() function, 285
lambda expression, 114–115, 117–118
late binding, 115
lazy evaluation, 116, 214
__le__() method, 93
left-fold operations, 128
len() function, 10, 47, 50, 51, 159, 298, 302, 306, 309–310, 313
__len__() method, 28, 93, 95, 159–160, 308
libraries, 235
line endings, see newline characters
lineno attribute, 317
list class, 14, 80
list comprehension, 17, 52, 55
filtering with, 127
list() function, 20, 47, 55, 81, 168, 306
listdir() function, 264
lists, 13–15
adding items to, 13, 307
as literals, 38, 46
as sequences, 47
assignments on, 83
comparing, 42
concatenating, 14
converting to, from data, 14
creating, 13
deep vs. shallow copies of, 83, 306
defining subtypes of, 81
empty, 14, 43–44, 306
iterating over, 13, 21
modifying, 49–50
nested, 14, 145–146
number of items in, 306–307
passed as function parameters, 107
processing, 52–53, 307
removing items from, 307
slicing, 14
sorting, 307, 310
literals, 37–38
ljust() method, 299, 311
load() function, 268
loads() function, 280
locals() function, 131, 303, 307
localtime() function, 293
Lock class, 291
locks, 25
Logger instance, 280–281
logging module, 254, 280–281
logical operators, 6–7, 43, 57, 92
LookupError exception, 67–68, 314, 316
loops, 4, 7–9, 21–22, 60–63
aborting, 141
flag variables in, 63
numerical indices in, 61
skipping the reminder of, 8, 62
taking items from different sequences, 62
loose coupling, 167
lower() method, 10, 299, 311
__lshift__() method, 90
lstrip() method, 299, 311
__lt__() method, 93–94
main() function, 33, 281
__main__ module, 234
__main__.py file, 235, 239, 245
maketrans() method, 299, 311
map() function, 128, 307
mappings, 18–19, 128, 307
opeations on, 51–52
math module, 318
mathematical operations, 5, 40, 90–92
__matmul__() method, 90
max() function, 47, 94, 128, 307
MD5 algorithm, 278
memory
allocating, 82
reducing usage of, 55, 210–211
MemoryError exception, 68, 316
metaclass keyword, 218–219
metaclasses, 217–222
Method Resolution Order (MRO, 190–192, 222
methods, 79, 154
abstract, 185, 222
available on an object, 26
bound, 158, 183
decorating automatically, 222
defining, 215
fully qualified, 158
implementing, 213
internal, 176
internal variables in, 27
invoking, 154
magic (special), 154, 210
naming, 172, 176
public, 176
redefining, 28, 160
rewriting, 195
static, 173–176, 310
user-defined, 180
Microsoft Excel, 276
min() function, 47, 94, 128, 307
mixin classes, 188–192, 220
__mod__() method, 90
mode attribute, 263
module objects, 226
__module__ attribute, 129, 222
__module__ variable, 215
ModuleNotFoundError exception, 316
modules, 30–32, 225–235
as first-class objects, 242–243
caching, 227–228, 231–233
compiling, 233
debugging, 235
importing, 31, 225–227, 232–234
circular, 230–232
specific definitions from, 228–230
listing contents of, 31
locating, 226
names of, 222, 226, 234, 242
namespaces of, 242, 304
organizing, 33
reloading and unloading, 232–233
renaming, 227
standard library, 31, 273–296, 318–319
third-party, 32
modulo, 5, 307
monads, 123
__mro__ attribute, 190, 207, 222
__mul__() method, 88, 90
multiplication, 5
name attribute, 263
name mangling, 177–179
__name__ attribute, 106, 129, 222, 242
__name__ variable, 33, 234
named fields, 19
namedtuple() function, 134
NameError exception, 68, 111, 316–317
namespace packages, 237
namespaces, 31, 158, 226, 242
global, 112
local, 111
of classes, 215, 218
of packages, 239–240
nc program, 274, 286
__ne__() method, 93
__neg__() method, 91
network programs, 286, 288, 291
__new__() method, 89, 199–201, 219
new_class() function, 216–217
newline attribute, 260
newline characters, 260, 263, 301, 304
controlling, in output, 265
in input, 266
newlines attribute, 263
next() function, 139–141, 307
next() method, 317
__next__() method, 97, 140, 152
None value, 6, 43–44, 87, 102, 108–110
normalize() function, 295
not in operator, 45, 57
not operator, 6–7, 43, 57, 92
NotADirectoryError exception, 316
NotImplemented object, 91, 93
NotImplementedError exception, 68, 93, 316
numbers
comparing, 42
complex, 301, 303, 305
converting
from objects, 94–95
from strings, 11
to text, 250–251
floating-point, 5, 37–38, 250–251, 288, 303, 308, 315
nonempty, 43
precision of, 251
random, 319
sum of, 312
numpy package, 50, 88, 96, 263
object class, 190, 307
inheriting from, 160, 191
objects, 26–30, 79–99, 153
attributes of, 56
built-in, 222–223
checking against classes, 183
comparing, 42, 80, 92–94
converting to built-in types, 94–95
coroutine, 135
deep vs. shallow copies of, 83
first-class, 85–87, 115
hash values of, 93–94, 304
identity of, 80, 304
immutable, 102
implementing operators for, 79
initializing, 27
invoked likes functions, 98
iterable, 45
listing available methods of, 26
location of, 38–39
management of, 89–90
methods available on, 26
mutable, 41, 83–84, 107–108
reference count of, 81–83
references to, 83–84
representations of, 84–85, 297, 308
serialization of, 268–269
sorting, 94
state of, 154
types of, 79, 154
unpacking values of, 45–46, 60
values of, 79, 84–85
oct() function, 37, 95, 307
offset attribute, 317
open() function, 12, 15, 241, 256–261, 279, 307
operating-system functions, 281, 316, 319
operators, 39–40
arithmetic, 5, 40
augmented, 7, 41, 47, 92, 111
bitwise, 6, 40, 57
comparison, 6, 42–43, 93
implementing, 79
logical, 6–7, 43, 57, 92
precedence rules for, 56–58
or operator, 6–7, 43, 57, 92
__or__() method, 90
ord() function, 307
os module, 258, 281, 319
os._exit() method, 317
os.chdir(), os.getcwd() methods, 257
os.environ variable, 256
os.path module, 281–282
os.system() function, 284
OSError exception, 64–65, 67–68, 277, 314, 316–318
output, see input/output (I/O)
OverflowError exception, 67, 314, 316
__package__ attribute, 242
packages, 33–34, 235–242
data files of, 241–242
deploying, 243–244
exporting, 240–241
importing files within, 34
imports within, 237
installing, 36, 244
locating, 36
namespaces of, 239–240
naming, 243
submodules of, running as scripts, 238–239
third-party, 50
pandas library, 277
parameters, see functions, arguments of
parent classes, see base classes
partial() function, 98
partition() method, 299, 311
pass statement, 7, 60, 65
Path class, 282
path separators, 281
__path__ attribute, 242
pathlib module, 257, 264, 281–283
patterns, 176
performance, 55
exception handling and, 111
local variables and, 149–151
optimizing, 210, 220–221
type checks and, 81
PermissionError exception, 277, 316
pickle module, 268–269
pip command, 35–36, 244
poll() function, 285
pop() method, 27, 104, 300, 302, 307, 309
Popen class, 289
popitem() method, 302
__pos__() method, 91
POSIX standard, 281
pow() function, 5, 40, 307
__pow__() method, 90
power, in math, 5, 307
__prepare__() method, 219
primitive types, 3
print() function, 4, 11–13, 84, 265, 308
ProcessLookupError exception, 316
programs, see also code
creating, 2–3
executing, 1, 3, 234–235
loading, 228, 233
side effects in, 108
specifying interpreter in, 3
starting from packages, 244
structuring, 34–35, 59, 235
terminating, 26, 69
properties, 180–183
functions associated with, 207, 211
implementing, 211
@property decorator, 180–182, 308
protocols, 87–99
proxies, 104, 208
push() method, 27
.py suffix, 2, 3, 30, 226, 233
__pycache__ directory, 233
pytest library, 319
Python
applying design patterns to, 176
flexibility of, 86
indentation in, 4, 316
interactive mode of, 1–2
no internal variables in, 27
optimized mode of, 77
package index of, 243
runtime environment of, 254, 319
python shell, 1
PYTHONPATH environment variable, 234
__qualname__ attribute, 129, 222
__qualname__ variable, 215
Queue class, 292
quit(), in REPL, 2
__radd__() method, 90–91
raise statement, 25, 64, 69
__rand__() method, 91
random module, 319
range() function, 21–22, 308
raw_input() function, 315
__rdivmod__() method, 90
re module, 283–284, 319
read() function, 258
read() method, 12, 262, 315
read-evaluation-print loop (REPL), 1
readable() method, 262
readinto() method, 262–263
readline() method, 262, 315
readlines() method, 262
recursion, 114
limit of, 114, 143, 317
RecursionError exception, 317
reduce() function, 128
reference counting, 81–83, 201
reference cycle, 203
ReferenceError exception, 317
registries, 194, 197, 222
regular expressions, 283–284, 319
reload() function, 232
remote servers, 208
remove() method, 18, 50, 300, 307, 309
removeprefix() method, 299, 312
removesuffix() method, 299, 312
replace() method, 10, 299, 312
repr() function, 11, 85, 89, 252, 308
__repr__() method, 28, 89–90, 154–155, 159–199
default implementation of, 160
requests library, 279, 294
resources, controlling, 99
return statement, 59, 109, 135, 140
reverse() method, 300, 307
reversed() function, 97, 308
__reversed__() method, 97, 308
rfind() method, 299, 312
__rfloordiv__() method, 90
rglob() function, 264
rindex(), rjust() methods, 299, 312
__rlshift__() method, 91
__rmatmul__(), __rmod__(), __rmul__()
methods, 90
__ror__(), __round__() methods, 91
round() function, 5, 40, 308
rpartition(), rsplit() methods, 299, 312
__rpow__() method, 90
__rrshift__() method, 91
__rshift__() method, 90
rstrip() method, 300, 312
__rsub__(), __rtruediv__() methods, 90
run() function, 135, 270–271
RuntimeError exception, 68, 114, 316–317
__rxor__() method, 91
sandbox, 36
scripts, 32–33
seek(), seekable() methods, 262
select module, 271, 284–285
select() function, 285
selectors module, 271, 285
self object, 27, 154, 158, 169, 220
send() method, 152
sep keyword, 265, 308
sequences
comparing, 43
mutable, 49–50
operations on, 47–50
set comprehension, 17, 53
set() function, 17–18, 20, 47, 309
__set__() method, 211
__set_name__() method, 212
setattr() function, 157, 179, 310
__setattr__() method, 98, 207, 211
setdefault() method, 302
__setitem__() method, 95–96, 167
sets, 17–18
adding/removing items to/from, 50, 309
as literals, 38, 46
creating, 17, 309
empty, 18
immutable, 304
number of items in, 50, 306, 309
order of elements in, 17
processing, 50–51, 53–54, 309
__setstate__() method, 268
setup() function, 244
setup.py file, 244
setuptools module, 234, 243–244
SHA-1 algorithm, 278
shallow copies, 83
shell, 1, 284, 319
short-circuit evaluation, 43
shutil module, 284, 319
side effects, 108
SIGINT signal, 69
signal module, 69
signature() function, 130–131
__signature__ attribute, 131
Simple Mail Transfer Protocol (SMTP), 285
sin() function, 318
singletons, 176, 200
site-packages directory, 35, 244
sleep() function, 293
slice instance, 96
slice() function, 310
slicing operator, 10, 47–49, 298, 307, 310, 313
implementing, 96
on lists, 14
on tuples, 16
__slots__ variable, 210–211, 220–221, 223
smtplib module, 285–286
socket module, 286–287
sort() method, 108, 307
sorted() function, 47, 114, 310
splatting, 46
split() function, 281
split() method, 10, 300, 312
splitlines() method, 300, 312
sprintf() function (C), 253
sqrt() function, 38, 318
stack frames, 132–133
stack traceback objects, 65, 73
standard error, 263
standard input/output, 263, 304
start keyword, 62
startswith() method, 10, 300, 312
state machines, 176
statements, 59
executing, 303
@staticmethod decorator, 125, 173, 183, 213, 310
statistics module, 47, 319
stdin, stdout attributes, 289
StopAsyncIteration exception, 317
StopIteration exception, 67, 69, 97, 140–141, 147, 307, 317
str() function, 11, 84, 94, 168, 248, 251–252, 310
__str__() method, 94, 171, 310
default implementation of, 160
strategy pattern, 176
strerror attribute, 316
stride argument, 48, 49, 96
StringIO class, 279
strings, 3, 9–12
as literals, 38
as sequences, 47
checking characters of, 311
comparing, 43
concatenating, 10–11, 310
converting
from non-string values, 11, 304
from objects, 94
to numbers, 11
converting to upper/lowercase, 310–312
creating, 11, 310
encoding/decoding, 310
formatting, 9, 11, 250–253, 310–311
iterating over, 21
methods for, 10
nonempty, 43
number of items in, 10, 306, 310
processing, 310–312
representations of, 89–90
substrings of, 10, 310–312
triple-quoted, 9, 38
whitespace in, 312
strip() method, 10, 300, 312
struct module, 288
struct_time object, 293
__sub__() method, 90
subclasses, 81, 160
checking classes against, 184, 305
implementing interfaces, 185
subprocess module, 256, 288–289
subtraction, 5
subtypes, see subclasses
sum() function, 15, 47, 128, 312
super() function, 161, 189–192, 199, 207, 313
superclasses, see base classes
swapcase() method, 300, 312
symmetric difference operation, 18, 50, 309
symmetric_difference() method, 309
symmetric_difference_update() method, 309
SyntaxError exception, 316, 317
sys module, 15, 319
sys.argv list, 33, 254–255
sys.exit() function, 317
sys.getdefaultencoding() method, 259
sys.getfilesystemencoding() function, 257, 264
sys._getframe() function, 132
sys.getrecursionlimit() function, 114
sys.getrefcount() function, 82
sys.modules variable, 227, 232
sys.path variable, 31, 35, 226, 234, 244
sys.setrecursionlimit() function, 114
sys.stderr object, 69, 263–264
sys.stdin, sys.stdout objects, 263–264
SystemError exception, 317
SystemExit exception, 15, 26, 67, 69, 314, 317
TabError exception, 317
tabulation, 19, 311, 318
teletypewriter (TTY), 281
tell() method, 262
telnet program, 274, 286
tempfile module, 289–290
testing
smaller tasks, 145
using file objects for, 279
text, 247–248
converting from binary data, 274
encoding/decoding, 13, 248–250, 255, 259
fitting to terminal width, 290
handling lines of, 260, 263
text attribute, 317
TextIOWrapper class, 260
textwrap module, 290
threading module, 271, 291–293
threads, 271–272
throw() method, 147, 152
time module, 293, 319
time() function, 293
time, handling, 293, 318–319
TimeoutError exception, 316
title() method, 300, 312
to_bytes() method, 305
@trace decorator, 125–126
traceback messages, 24, 315
traceback module, 73
__traceback__ attribute, 65, 73, 315
translate() method, 299–300, 312
True value, 6–7, 38, 43–45, 297–298
__truediv__() method, 90
__trunc__() method, 91
truncate() method, 262
truncating division, 5
try statement, 24–25, 64, 66, 110, 141
tuple type, 313
tuple() function, 47
tuples, 15–17
as keys, 52
as literals, 38, 46
as sequences, 47
comparing, 42
concatenating, 16
creating, 15
empty, 43, 313
indexing, 16
iterating over, 17, 21
named, 109–110
number of items in, 306, 313
returning values from functions with, 23, 109
slicing, 16
unpacking, 16
using in dictionaries, 19
turtle module, 319
type class, 218–220, 313
type hints, 107, 129, 155, 179–180, 222
creating methods from, 197
module-level, 242
with base classes, 184–185
type() function, 70, 80, 154, 217, 313
type-based dispatch, 193–194
TypeError exception, 43, 68, 95, 101, 103, 122, 191, 211, 305, 317
types, 79, 313
built-in, 167–169
checking values against, 81, 305
conversions between, 94–95
types module, 313
UDP servers, 287
unary minus/plus, 5
UnboundLocalError exception, 68, 111, 317
Unicode encoding
code-point values in, 307
in source code, 2
operations on text strings in, 294–295
unicodedata module, 294–295
UnicodeError exception, 67–68, 249, 317
UnicodeXXXError exceptions, 317
union operation, 18, 50, 309
union() method, 309
unittest module, 319
universal newline mode, 260
UNIX
EOF character on, 2
executing files on, 3
low-level I/O control operations on, 278
newline characters on, 260
path separators on, 281
unpack() function, 288
update() method, 18, 168, 302
upper() method, 10, 300, 312
urlencode(), urlopen(), urlparse() functions, 293–294
urllib package, 293–294
urllib.parse package, 294
UserDict, UserList, UserString classes, 168
UTF-8 encoding, 2, 13, 249–250
ValueError exception, 25, 67–68, 317
values, 3, 79
checking against types, 81, 305
minimum/maximum, 307
printing, 265, 308
reducing, 128
representing, 84–85
updating in place, 41
values() method, 21, 51, 302
variables, 3
associated types of, 3, 167
free, 114–115
global, 111–113
local, 24, 111–113, 134, 149–151
names of, 3
reassigning, 108
starred, 46
type hints for, 107
unbound, 317
vars() function, 313
venv command, 36
virtual environment, 36
walrus operator, see := operator
warning() function, 281
weak references, 204–206, 317
weakref module, 204, 317
__weakref__ attribute, 206
web servers, 279
websites, 275, 294
while statement, 4, 7–9, 12, 39, 60–62
Windows
EOF character on, 2
executing files on, 3
failed system calls on, 318
newline characters on, 260
path separators on, 281
WindowsError exception, 318
with statement, 12, 25, 75–77, 99, 202, 256, 289–290
wrap() function, 290
wrappers, 104, 208
@wraps decorator, 124–125
writable() method, 262
write() function, 265
write() method, 13, 262
write_through attribute, 263
writelines() method, 262
xml package, 295–296
xml.etree package, 295
__xor__() method, 90
yield from statement, 142–143
yield statement, 97, 139–142, 265
used as an expression, 146–147
ZeroDivisionError exception, 67, 314, 318
zfill() method, 300, 312
zip() function, 62, 314
© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers
SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.