Table of Contents
Dead Simple Python Index
Return to Dead Simple Python, Python Bibliography, Python, Python DevOps - Python SRE - Python CI/CD, Cloud Native Python - Python Microservices - Serverless Python, Python Security - Python DevSecOps, Functional Python, Python Concurrency, Async Python, Python Data Science - Python and Databases, Python Machine Learning, Python Courses, Python Glossary, Awesome Python, Python GitHub, Python Topics
Symbols
!= (not equals) operator, 49
!r (representation flag), 58
“ (single quotes), 43, 54
”“ (double quotes), 43, 54
”“” (triple quotes), 43, 54–55, 57
alternative form flag, 58
hash or octothorpe, 42
% operator
modulo, 46, 47
%-interpolation, 346
& (and/intersection) operator, 47, 221, 343–344, 345
() (parentheses) operator, 46
multiplication, 46
starred expression, 226
variadic parameter, 130–131
wildcard, 527
** operator
exponent, 46
keyword variadic parameter, 131
+ operator
addition, 46
concatenation, 56, 62
flag, 58, 298
, (trailing comma), 126, 217, 226
- operator
sign flag, 58
subtraction/difference, 46, 221
→ (return type annotation) operator, 146
. (dot) operator, 58, 64, 152, 429
.. (parent directory), 84, 322
… (Ellipsis), 53, 146
… prompt, 18
division, 46
in paths, 318, 321
in positional parameters, 133
// (floor division) operator, 46, 47
: (colon), 42, 63, 222, 279
:= (assignment expression/walrus) operator, 52–53
; (semicolon), 40
< operator
align left flag, 58
less than, 49
⇐ (less than or equals) operator, 49
« (left shift) operator, 47, 345
== (equals) operator, 49, 97–98
= operator
alignment flag, 58
assignment, 44, 47
align right flag, 58
greater than, 49
= (greater than or equals) operator, 49
(right shift) operator, 47, 345
@ operator, 47, 144
[] (square brackets), 65–66, 222, 277
\ (backslash) character, 54, 55–56
\n (newline), 55, 56, 294, 307
\t (tab), 293–294
\r (carriage return), 294, 307
align center flag, 58
exclusive or/symmetric difference, 47, 221, 344, 345
_ (underscore) character
as name, 226, 227
nonpublic flag, 156
as wildcard, 68
__ (naming convention), 157, 167
{} (curly braces), 57, 61, 220, 222, 278, 279
bitwise inversion operator, 47, 344–345
in UNIX folder system, 321–322
0 (leading zeros flag), 58
A
__abs__() method, 174, 641
absolute imports, 83
absolute paths, 316–320, 325
abstract base classes (ABCs)
about, 410–411
built-in, 411–412
custom, 415–417
deriving from, 412–415
abstract syntax tree (AST), 571
@abstractmethod decorator, 415
accelerator modules, 629
accumulate() (itertools module) function, 252
addition (+) operator, 46, 298
__aenter__() method, 475, 639
Aesera, 625–626
aioconsole library, 469–470
about, 117
function names, 80
mutable data types, 108, 110
with type hints, 146
alignment flags, 58
all() function, 248
Anaconda, 35–36, 624, 625
anchors, 316–317
__and__() method, 174, 345, 642
and operator, 51–52
annotations, 145–147
__annotations__ attribute, 146, 645
anonymous callables, 652
anti-pattern examples, 86, 131, 150, 190–192, 374, 385
any() function, 248
appendleft() method, 220
AppImage, 538–539
application development, 621–622
arbitrary arguments lists. See variadic arguments
arbitrary execution, 454–456, 652
argparse, 554
about, 123, 652
keyword and positional, 128–129
variadic, 130–132
arithmetic shift operations, 345
ArithmeticError class, 209
Arnold, Tim, 626
arrays, 219
artifacts, 652
Åsheim, Eiríkr, 486
assembling, 6
AssertionError, 556–557
assertions (assert statements), 556–560, 653
assignment, 107–109, 117. See also binding
assignment expressions, 44, 47, 52–53, 369–370
async keyword, 464, 653
async with statement, 475
asynchronous context managers, 475
asynchronous generators, 475
asynchronous iteration, 472–475
and coding safety, 486
in Collatz game example, 465–469
with context managers, 475
with generators, 475
with iterations, 472–475
in Python, 459–460
scheduling and execution flow, 470–472
vs. threading, 478
uses of, 463–464
AttributeError, 157, 164, 209
about, 150, 154, 653–654
checking for, 408–410
class, 105–106, 154, 155–156
deleting, 433
of functions, 433–436
inspecting, 426–431
instance, 151, 152, 154–155
scope naming conventions, 156–157
setting, 431–433
and structural pattern matching, 177–180
Atwood, Jeff, 185
augmented assignment operators, 47
automation development, 627
autouse fixtures, 603–604, 665
await keyword, 464–465
awaitables, 464
B
backslash (\) character, 54, 55–56, 347
Bandit, 571–574
BaseException class, 207, 209
__bases__ attribute, 646
basicConfig() (logging module) function, 196, 199
Batchelder, Ned, 95, 99, 107, 456, 609
bdist (built distribution), 516, 531
Beazley, David, 460
benchmarking, 611, 612–613
big data, 623
big-endian byte order, 342–343, 349
binary extension modules, 629–630
binary notation, 338–343
binary operator special methods, 173–174
about, 295
changing stream positions, 371
custom format example, 364–368
modes, 298
opening, 363
reading from, 368–370
binding. See also assignment
about, 117, 654
to copies, 111–114
references, 109
weakly bound, 44
binding behavior, 436, 655
bitmasks, 341
bits, 338
on bytes-like objects, 357–361
and custom classes, 346
operators, 47, 343–346
black box behaviors, 150
Black tool, 34
boilerplate code, 151
Bokeh, 624
bool() function, 237–238
__bool__() method, 171, 638
boolean values, 51, 237–238, 345
boolean variables, 50–51
break statement, 67, 214
breakpoints, 561
brittle code, 247, 556
Brython (Browser Python), 623
BSON serialization format, 376
bubbling up, 199–200
buffer protocol, 361
BufferError, 209
buffers, 291–292, 655
build system (pyproject.toml), 529–530
built distribution (bdist), 516, 531
__builtins__, 645
bullet journal example, 385–388
bytearray objects, 348, 363
bytecode, 6, 91
byteorder attribute, 349
bytes
defined, 338
order, 342–343, 349–350, 352, 656
bytes() method, 348–349
__bytes__() method, 171, 638
about, 347
bitwise operations on, 357–361
bytes vs. bytearray, 348
creating, 348–349
and integer conversions, 349–351
and memory consumption, 361–363
sequence operations, 351
and struct module, 352
bytes literals, 346–347
BytesWarning, 545
C
C Foreign Function Interface (CFFI), 629
C3 Method Resolution Order (C3 MRO), 389–392, 395
__cached__ attribute, 644
cached bytecode, 91
Call for Proposals (CFPs), 634
__call__() method, 175–176, 638
call stacks, 186–187
callable instances, 175–176
callable objects (callables), 131–132, 656
callbacks, 465
camel case, 656
canonical string representation, 61, 168–169
capture patterns, 69–70
cargo cult programming, 514, 657
carriage return (\r), 294, 307
CBOR (Concise Binary Object Representation) serialization format, 376
__ceil__() method, 171, 638
chain() (itertools module) function, 252
chr() function, 161
chunking, 501
CircuitPython, 627
class attributes, 105–106, 646
__class_getitem__() method, 644
class methods, 158–159
classes. See also abstract base classes (ABCs); inheritance; metaclasses; virtual subclasses
about, 150
and bitwise operations, 346
decisions about using, 181–182
declaring, 151–154
as immutable, 447–449
and SOLID principles, 382–384
syntax, 63–64
classifiers (PyPI), 522–523
@classmethod decorator, 159
clauses, 657
closing generators, 264–266
closures, 135–138
coarse-grained locking, 487–488
autoformatting, 33–34
boilerplate, 151
brittle, 247, 556
“dead”, 608
editors, 34–36
frozen, 666
security evaluation, 571–574
style, 27–29, 31
testing frameworks, 34
and thread safety, 486–488
tightly coupled, 120
__code__ attribute, 645
code coverage, 607–609
code injection, 455
coercion, 114, 117, 658
with asynchronous iterable, 472–473
with coroutines, 465–472
with futures, 483–486, 496–497
with multiprocessing, 500–501
producer/consumer implementation, 502–507
with queue, 495–496
with race conditions, 489–493
synchronous version, 461–463
threading, 479–481, 482
about, 65, 66, 216
checking for values in, 236–237
deques, 219–220
dictionaries, 222–225
length, 237–238
lists, 218–219
and references, 109–114
sets, 220–222
subscriptable, 231
tuples, 216–218
unpacking, 225–228
collections module, 217, 411
combinations() (itertools module) function, 252
command line prompts, 18
comments, 42–43
comparison methods, 171–173
comparison operators, 49
compiling, 6
__complex__() method, 171, 638
complex numbers (complex), 45
compositions, 150–151, 181, 384
compound statements, 41
in printing, 292
string literals, 55
strings, 56, 62
concrete exceptions, 209–210
concrete paths, 316
concurrency, 458, 478
concurrent.futures module, 483–486, 496–497, 508
conditionals, 41, 49, 273–276. See also ternary expressions
conferences, 634
configparser module, 332
configuration files, 332–333, 334
constants, 44–45, 47–48
constructors, 152–153
containers, 537–539
__contains__() method, 237, 254, 639
context management protocol, 309–314
about, 296–297
asynchronous, 475
operations, 308–314
context variables (contextvars), 476
controller class]]es, 384
conversions, 114–115, 117, 168–171
copying, 111–114, 117, 235
core developers, 631, 659
about, 282–283, 287
native, 464–466
simple, 283–286
count() (itertools module) function, 258
Counter, 224
coverage.py tool, 607
cprofile module, 613–617
CPU-bound tasks, 463, 497–498
CPython, 5, 627, 628
CSV (comma-separated values) file format, 332
ctrace module, 607
cumulative runtime, 614
Curio library, 460, 466, 468
current working directory, 322, 324–325
cx_Freeze, 5, 6, 536
cycle() (itertools module) function, 258
Cython transpiler, 5, 630
D
daemonic threads, 482–483, 660
Dask, 624
defined, 117
picklable, 499
data descriptors, 437
data hiding, 157
data science, 623–625
in binary data conversions, 353
mutable and immutable, 106–107
treatment in Python, 44, 98–100
data validation vs. assertion, 558–559
dataclasses, 449
dataframes, 624
deactivate command, 20
deadlocks, 493–494
debugging. See also logging; Python Debugger (pdb)
and assertions, 556–560
example, 561–562
loops vs. generator expressions, 281–282
and packaging, 514–515
tools, 560–561
and warnings, 544–548
Decimal number type, 45–46
about, 660
class, 176–177
defining properties with, 164–166
on functions, 142–145, 436
deep copy (deepcopy()), 113–114, 117
def keyword, 63
default argument values, 126–128, 146
defaultdict, 224
__defaults__ attribute, 645
del operator, 154, 223
__delattr__() method, 433, 643
__delete__() method, 437, 639
deleters, 162–163
__delitem__() method, 231, 235, 639
dependencies, 15–16, 22–23, 524–525, 537–539
dependency injections, 587
Dependency Inversion Principle, 383–384
DeprecationWarning, 545
about, 436–437, 661
writing, 437–442
deserialization. See serialization
design patterns, 373, 407–408
development environments. See also IDEs (integrated development environments)
and requirements.txt file, 528–529
dialects, 332
diamond inheritance problem, 389
diaper anti-pattern, 190–192
closures, 135–138
with default arguments, 125–128
with keyword arguments, 128–134
with recursion, 124–125, 134–135
with type hints, 145–146
about, 426–428, 645, 646
listing, 428–429
vs. slots, 444–445
about, 222–224
unpacking, 227–228
variants, 224–225
dictionary comprehensions, 279
difference (-) set operator, 221
dir() function, 429
__dir__() method, 429, 643
directories. See also paths
dist/, 531
src/, 517–518, 580
virtual environment, 19, 23–24
discard() method, 221
dist/ directory, 531
divmod() function, 47
__divmod__() method, 174, 640
Django, 622
__doc__ attribute, 644, 645, 646
Docker, 539
docstrings, 43, 58, 434, 541, 662
project, 540–541
Python, 9
with type hints and annotations, 145–147
dot operator (.), 64, 105, 152, 429
drive (in path names), 318, 319
dropwhile() (itertools module) function, 252
duck typing, 100, 114, 146–147, 384, 408–410
dump() (json module) function, 329–330
dumps() (json module) function, 329–330
dunder methods. See special methods
dynamic vs. static typing, 6, 44, 98–99
E
e (Euler's number) constant, 48
EAFP (Easier to Ask Forgiveness than Permission)
philosophy, 187–188
Eclipse, 36
editable package installations, 531
definition, 445–446
functions, 449–452
as immutable, 447–449
usage, 452–454
Ellipsis (…), 53, 146
else clause, 41, 49, 202–204, 215–216
Emacs, 34–35
embedded development, 626–627
empty sets, 221
encapsulation, 150, 182, 663
enclosing scope, 105
encryption, 373–374
endianness, 342–343
__enter__()]] method, 308–309, 311, 638
entry points, 85–86, 86–87, 88–89, 525–526
enumerate() iterable, 244, 248
__eq__() (equals) method, 170, 172, 640
equals, 49, 97–98, 172
Eric Python IDE, 36
errors, 663. See also debugging; exceptions
escape characters, 54, 55–56, 61, 347
eval() function, 454–456
event handler functions, 504
event loops, 459–460, 468
example projects. See Collatz game example; dice roll program example; Element class example; GlobalCoordinates class example; omission project example; SecretAgent class example; textproof project example; Timecard packaging example
except clause, 187, 189–190, 200
Exception class, 207, 209
exceptional state, 190
about, 184–186
bubbling up, 199–200
catching, 64–65, 187–190
chaining, 200–202
vs. checking, 223–224
converting from warnings, 548
and diaper anti-pattern, 190–192
and dictionaries, 223–224
extracting information with, 194–195
list of, 208–210
and logging, 195–199
raising, 192–194, 408
throwing, 266–268
and tracebacks, 186–187
exec() function, 454–456
executors, 484–485
exists() (path module) method, 326
exit() command, 18
__exit__() method, 308–309, 311–312, 638
expressions, 40
extension development, 629–630
F
f-strings (formatted strings), 56–60
False and True values, 51, 237–238, 345
FastAPI, 623
faulthandler module, 570–571
__file__ attribute, 325, 426, 644
file formats, 328–335
file modes, 297–299, 303
file objects. See streams
FileHandler objects, 550–551
files. See also JSON files; paths; streams
closing, 296–297
opening, 295–296, 297–299
Python code (.py) files, 18, 75
reading, 299–302
replacing, 327–328
writing to, 303–307
Filter (logging module) objects, 555
filterfalse() (itertools module) function, 252
finalizers, 153–154
finder objects, 90
Fitzpatrick, Martin, 622
fixtures, 586–588, 664–665
Flake8, 31–33, 530
.flake8 files, 32
flaky tests, 591
Flask, 622–623
Flatpak, 537–538
Flit, 534
floating-point numbers (float), 45, 46, 106, 353, 354, 665
floor division (//) operator, 46, 47
__floor__() method, 171, 638
__floordiv__() method, 174, 640
flush= keyword, 292
flushing, 291–292
fman Build System, 536–537
Foerster, Daniel, 360
for loops, 67–68, 215–216, 242–244
binary data conversion, 352–353
f-strings, 58–59
For[[matter (logging module) objects, 555–556
Fraction number type, 45–46
Freeze, 5
freezers, 5, 535–537
freezing, 665
from_bytes() method, 351
frozenset, 221–222
function annotations, 145–146
functional programming, 119, 120–122, 180
aliases, 80
with lambdas, 140–141
list of special attributes on, 645
and methods, 64
nested, 104–105, 134–135
overloaded, 129–130
passing, 139–140
pure, 121–122
shadowing, 79–80, 81–82
side effects, 108
single-dispatch generic, 449–452
syntax, 62–63
functools module, 143, 144
futureproofing, 373
futures, 666. See also concurrent.futures module
fuzzing, 605
G
Gábor, Bernát, 519
game development, 622
garbage collection, 100–101, 106, 153–154, 667
gather() (asyncio module) function, 472
__ge__() method, 173, 410, 640
generational garbage collection, 106
about, 123, 270–271
with conditionals, 273–276
evaluation of, 271–272
vs. list comprehensions, 277–278
with nesting, 276–277
about, 259–261
closing, 264–266
throwing exception with, 266–268
and yield from statements, 268–270
asynchronous, 475
as coroutines, 286
vs. generator expressions, 282
generic functions. See single-dispatch generic functions
generic types, 146
__get__() method, 437, 639
getattr() function, 429
__getattr()__ method, 429–431, 643
__getattribute()__ method, 429–431
get_event_loop() function, 468
__getitem__() method, 231, 235, 639
getters, 150, 161–163
Git, 23–24, 74
Glassner, Andrew, 626
glob() (path module) method, 326
Global Interpreter Lock (GIL), 459, 478, 498
global scope, 100, 102–104, 105
GlobalCoordinates() class example, 167–170, 172, 173, 174, 175–176
god classes, 181, 385, 667
Goldberg, David, 45
greater than, 49, 172–173
__gt__() (greater than) method, 172–173, 640
GTK GUI framework, 621
GUI frameworks, 621–622
H
and embedded development, 626–627
package deployment on, 541
has-a relationships, 151
hasattr() function, 408–410, 431
__hash__() method, 170, 220, 639
Hashemi, Mahmoud, 515, 535
HDF (Hierarchical Data Format), 376–377
headers, 41
heterogeneous collections, 66
Hettinger, Raymond, 395
hexspeak, 339–340
high-performance computing (HPC), 497
home() (PosixPath module) method, 321
homogeneous collections, 66
hooks, 90, 668
HTML file format, 333
human-readable string representation, 61, 169–170
Hungarian Notation, 115–116
Hypothesis framework, 579
I
__iadd__() method, 174, 641
__iand__() method, 174, 643
id() function, 98
defined, 117
operator (is), 50–51
and values, 97–98
IDEs (integrated development environments), 34–36, 145–146
IDLE, 34
if clauses, 41, 49
__ifloordiv__() method, 174, 642
__ilshift__() method, 174, 643
__imatmul__() method, 174, 642
about, 65–66, 117, 216
data types, 106–107
making classes as, 447–449
__imod__() method, 174, 642
absolute vs. relative, 83–85
cont[[rolling, 87–88
executing, 77
process, 90–91
and shadowing prevention, 79–80
__imul__() method, 174, 641
in operator, 67, 236–237
indentation, 29, 41
IndentationError, 210
indices (subscripts), 217, 231–235
inf (infinity) constant, 45, 47, 48
information security (infosec) field, 626
inheritance. See also method resolution order; multiple inheritance
about, 151, 382
bullet journal example, 385–388
and slots, 446
and SOLID principles, 382–384
when to use, 384–385
INI file format, 332–333
__init__() method, 64, 151–152, 643
__init__.py file, 74–75, 76, 86, 87–88
__init_subclass__() method, 643
methods, 151–152, 159
with multiple inheritance, 396–398
input() function, 40, 294–295, 469
mocking, 592, 597–598
validation vs. assertion, 558–559
instance attributes, 151–152, 645
__instancecheck__() method, 418, 643
about, 150, 670
making callable, 175–176
__int__() method, 171, 638
integers (int), 45, 106, 340–341, 343
integrated development environments (IDEs), 34–36, 145–146
integration tests, 605
interactive sessions, 17–18
Interface Segregation Principle, 383
and abstract base classes, 410–411
in SOLID principles, 382, 383
and virtual subclasses, 418
interpreted languages, 5
interpreter shutdown, 102
intersection (&) set operator, 221
introspection, 425, 426, 454, 670
__inv__() method, 345
invalid number constant (nan), 45
__invert__() method, 174, 345, 642
__ior__() method, 174, 643
__ipow__() method, 174, 642
IronPython, 628
__irshift__() method, 174, 643
is not operator, 51
is operator, 50–51, 97–98
is-a relationships, 151, 382
is_absolute() (path module) method, 326
is_dir() (path module) method, 326
is_file() (path module) method, 326
is_symlink() (path module) method, 326
islice() (itertools module) method, 235–236, 252
__isub__() method, 173, 174, 641
items() method, 228
__iter__() method, 238–239, 255, 638
about, 238
custom classes, 253–256
tools, 248–252
type-hinting, 147
iteration. See also iterables; loops
about, 215, 238–239
asynchronous, 472–475
with for loops, 242–243
manual, 239–241
tools for, 248–251
iterator classes vs. generator functions, 261–263
infinite, 258–259
and lazy evaluation, 257–258
streams as, 301–302
iterdir() (path module) method, 326
itertools module, 252
__itruediv__() method, 174, 642
__ixor__() method, 174, 643
J
JetBrains, 35
JSON (JavaScript Object Notation) files, 329–332
just-in-time (JIT) compilers, 627
Jython, 628
K
Kedro, 624
Keen, Kyle, 258
Keras, 625
KeyboardInterrupt, 191, 198, 209
keyword arguments, 128–129
keyword-only parameters, 132–133
keyword variadic parameters, 131
Kivy GUI toolkit, 621
Kneusel, Ronald T., 626
**kwargs parameter, 131–132, 398
L
lambdas, 119, 138–141, 145
interpreted vs. assembled, 5
static vs. dynamic typing, 44, 98–99
LanguageTool API, 579, 588–589
lazy evaluation, 257–258, 270, 271–272, 671
LBYL (Look Before You Leap)
checking for conditions, 188, 224, 408–410
philosophy, 187
__le__() method, 173, 640
leading zeros flag, 58
left shift («) operator, 47, 345
LEGB (scope resolution) acronym, 105
len() function, 237, 254
__len__() method, 254, 358, 639
less than, 49, 172–173
LICENSE file, 74, 518, 519–520, 521
LiClipse, 36
lightning talks, 634
line separators, 307
link_to() (path module) method, 326
linters, 29, 31
build dependencies, 15–16
and packaging, 537, 539–540
Python and pip installer, 15
Liskov Substitution Principle, 383
list comprehensions, 110, 277–278
lists
about, 218–219
mutability, 107–108
syntax, 65
little-endian byte order, 342–343
livelocks, 493–494
load() (json module) function, 331
loads() (json module) function, 331
local scope, 100, 101, 104–105
locks and locking, 487–488, 492–494. See also Global Interpreter Lock (GIL)
about, 195, 507–508, 548–549, 556
examples, 195–199, 549–555
filters, 555
for[[matters, 555–556
severity levels, 196, 549, 552
assigning severity levels, 552–554
configuring, 196, 199
objects, 549–551, 555–556
LogRecord objects, 549, 550, 553
Look Before You Leap (LBYL). See LBYL (Look Before You Leap)
loops
cont[[rolling, 67
enumerating items in, 244
vs. generator expressions, 281–282
for loops, 67–68, 215–216, 242–244
mutating items in, 244–246
nested, 247–248
in programming guidelines, 121
while loops, 66, 214–215
loose coupling technique, 383–384
__lshift__() method, 174, 345, 642
__lt__() method, 172–173, 640
Lubarsky's Law of Cybernetic Entomology, 543
M
machine learning/training, 625–626
Python and pip installer, 14
magic methods. See special methods
MANIFEST.in file, 518, 527–528
map iterable, 250–251
map() method, 491
mapping, 222
mappingproxy, 427–428
Marick, Brian, 609
Märies, Ionel Cristian, 517
marking, 598–600, 672
marshal module, 374
__match_args__ attribute, 179–180
math module, 47–48
math operations and constants, 45–48, 221–222
__matmul__() method, 174, 640
Matplotlib, 624
matrix multiplication (@) operator, 47
max() function, 248
McA’Nulty, Pamela, 507
McCabe complexity, 31, 32
member variables. See instance attributes
MessagePack serialization format, 376
and base class order, 392–395
example, 388–392
methods. See also special methods
about, 64, 150
and functional programming, 180
inspecting, 426–428
types, 158–160
min() function, 248
Minecraft .dat file, 373
__missing__() method, 639
mixins, 399–401
mkdir() (path module) method, 326
__mod__() method, 174, 640
modification in place, 106
__module__ attribute, 645, 646
module search paths, 89–91
ModuleNotFoundError, 77, 91, 209
about, 74–75
entry points, 85–86
frozen, 90
naming conventions, 75
special attributes on, 644–645
updating, 518
monkeypatching (monkeypatch tool), 597, 604–605
__mro__ attribute, 388, 646
__mul__() method, 174, 640
multiline string literals, 55
and base class order, 392–395
cont[[rolling resolution, 395–398
and metaclasses, 407
method resolution order, 388–392
multiplication (*) operator, 46
multiprocessing. See also producer/consumer problem
about, 477, 498–499
with Collatz game example, 500–501
logging with, 507–508
and pickle, 499–500
multiprocessing module, 498, 503, 505, 508
multisets, 224
multitasking, 458, 459, 478
multithreading, 478
about, 117
binding to, 109–114
data types, 106–107, 121
avoiding, 110–111
defined, 117
effects of, 104, 106–107
in loops, 244–246
Muthukadan, Baiju, 602
Mypy, 33, 145
N
__name__ attribute, 85–86, 426, 645, 646
named tuples (namedtuple), 217–218
names
about, 96, 99, 117
global scope, 102–104
local scope, 100, 101
constants, 44–45
and Systems Hungarian Notation, 115–116
unit tests, 588
nan (invalid number) constant, 45, 47, 48
__ne__() (not equals) method, 172, 640
__neg__() (negative sign) method, 175, 641
negative binary notation, 343, 344–345, 350–351
negative numbers, 58, 175, 341
functions, 134–135
generator expressions, 276–277
loops vs. alternatives, 247–248, 272–273
and scope, 104–105
statements, 41
NetCDF (Network Common Data Form) serialization format, 376
neural networks, 625
__new__() method, 152–153, 406, 643, 644
newline (\n), 55, 56, 294, 307
next() function, 240–241
__next__() method, 238–241, 254–255, 259–260, 261, 638
non-data descriptors, 437
nose2 module, 578
not equals, 49, 172
not keyword, 51–52, 237
notebook documents (Jupyter), 623
NotImplemented, 197
NotImplementedError, 197
Nuitka transpiler, 5, 537
null termination, 354
Numba, 625
binary, 338
integers, 340–341
octal, 340
two's complement, 341
number types, 45–46
O
object-oriented programming, 120, 149–151, 180
objects. See also mutable objects
about, 150
callable, 131–132
creating, 63–64
inheritance, 151
slicing on, 235
oct() function, 341
octal numbers, 340
ODF (Open Document Format) file format, 334
odfpy library, 334
offset keyword, 371
entry point example, 88–89
importing example, 80–81, 82–85
setup, 74
one's complement (~), 47
Oolite (game), 373
Open-Closed Principle, 382–383
operators, 46–47
or keyword, 51–52
__or__() method, 174, 345, 642
or patterns, 69
ordered items, 217
os module, 315, 328
out-of-place testing, 580
overloaded functions, 129–130
overwrite (\r), 294, 307
P
pack() (struct module) method, 352, 353–355
package manager. See pip
packages. See also imports; uploads
about, 18–19, 74–75
contributing to, 628–629
editable, 531
entry points, 86–87
finding, 23
including files and additional, 523–524, 525
installing, 21–22, 531, 533
naming conventions, 75
provisional, 620
removing, 22–23
upgrading, 22
virtual environment access, 20, 21
distribution options, 515–517
for end user distribution, 534–540
planning, 514–515, 517–518
and relative paths, 323–325
resources on, 514
packaging gradient, 516, 535
packaging tools, 534. See also setuptools library
padding, 354–355, 360–361
Paige, Jeremiah, 519
Pandas, 624
about, 477, 497–498
vs. asynchrony, 459
vs. concurrency, 478
with multiprocessing, 498–501
about, 123, 676–677
and assignment, 107–109
positional and keyword, 132–134
type hints, 146–147
parametrization, 592, 594–596, 605
parent directory (..), 84, 318, 322
parentheses () operator, 46, 217
parents (path module) property, 317
partial() (functools module) function, 491
parts() (PurePath module) method, 317
passing messages technique, 487, 495–496
patches, 631
__path__ attribute, 74, 91, 644
path entry finders (path entries), 90–91
about, 315
classes, 315–316
operations, 320–323, 325–328
and path parts, 316–320
paths
about, 314
absolute, 316–320
modules, 315
objects, 315–316
relative, 322–325
patterns. See also anti-patterns
glob, 527
singleton, 407–408
structural matching, 68–71, 177–180, 228–230
virtual machine design, 373
pdb. See Python Debugger (pdb)
PendingDeprecationWarning, 545
PEP 8 (style guide), 27–29, 33–34, 75
PEP 20 (The Zen of Python), 8–9
PEPs (Python Enhancement Proposals), 9, 630
benchmarking, 611, 612–613
and concurrency, 458
exception handling, 187–189, 223–224
perceived responsiveness, 463–464
profiling, 577, 613–617
and programming paradigms, 121
permutations() (itertools module) function, 252
Peters, Tim, 8, 10, 404, 407
PEX (Python Executable), 535
pi constant, 47
pickle module, 374–375, 499–500
Pike, Rob, 478
pinning, 528
about, 21
pip install command, 21–22, 23, 528–529
Pipenv tool, 27
Pirnat, Mike, 190
place values, 339
.plist (property list) serialization format, 375
Poetry, 27, 534
polymorphism, 384
__pos__() method, 175, 641
positional arguments, 128–129
positional-only parameters, 133–134
POSIX file paths, 314, 319–320
PosixPath initializer, 320
__pow__() method, 174, 640
PowerShell, 19
pprint (pretty print) module, 427
__prepare__() method, 406, 644
Preston-Werner, Tom, 334
Price, Will, 607
priming, 678
print() function, 40, 290–294, 306–307
procedural programming, 120
about, 501–502
Collatz program implementation, 502–507
product() (itertools module) function, 248, 252
profiling, 577, 611
program entry points, 88–89
motivation, 11, 456, 635
paradigms, 120–122, 149
licensing, 519–520, 521
naming, 520–521
setup, 74, 77
versions, 521
virtual environments for, 19
working with, 6
about, 160, 679
application of, 166–167
defining with decorators, 164–166
property() function, 163, 164–165, 166
property list (.plist) serialization format, 375
Protocol Buffers (Google), 377
PureWindowsPath initializer, 320
py2app, 536
py2exe tool, 5
PyAutoGUI, 602
.pyc files, 6, 91
PyCharm, 35, 145
PyDev plug-in, 36
pydoc, 540
PyFlakes, 31
PyGame, 622
PyGObject, 621
PyLadies, 633
Pylint, 29–31
pylintrc file, 31
Pyodide, 623
PyOxidizer, 536
PyPI. See Python Package Index (PyPI)
pyproject.toml file, 518, 519, 529–530
PyPy, 627
PyRTF library, 334
about, 578
and C language, 352
contributing to, 630–631
developing for, 628–631
development of, 3–4
governance, 9
implementations, 627–628
installing, 14–17
principles and practices, 5–6, 7–9, 10–11, 121
reporting bugs and security flaws, 574
running, 17–18
versions, 6–7, 17
about, 560–561
inspecting and checking, 567–569
moving through execution stack, 565–566
postmortem use, 569–570
starting, 562–563
stepping through code, 563–565
about, 5, 6, 102
specifying path to, 24–25
Python Package Index (PyPI), 23, 516, 522, 629
Python Packaging Authority (PyPA), 515, 630
Python Software Foundation (PSF), 9, 634–635
PyTorch, 625
Q
Qt GUI framework, 602, 621
qualified vs. unqualified names, 70, 79, 666, 680
quality assurance (QA), 577
__qualname__ attribute, 645, 646
queues (queue module), 495–496, 503, 505, 508
quotation marks, 43, 54–55, 57
R
race conditions, 487, 488–489, 491–492
__radd__() method, 174, 641
radians() (math module) function, 48
radint() (random module) function, 122
__rand__() method, 174, 642
range() iterable, 67, 249
raw bytes literals, 347
__rdivmod__() method, 174, 641
read() method, 296, 299–300, 307
readline() method, 300–301, 307
README file, 74, 518, 519, 521
read-only descriptors, 437
read_text() (path module) method, 325
rebinding, 117. See also binding
recursion, 121, 124–125, 134–135, 136–137
reentrancy, 488, 502
reference-counting garbage collector, 100–101
references, 109–114, 117
register(), 451–452
relative imports, 83–85
relative paths, 322–325
rename() (path module) method, 326
repeat() (itertools module) function, 258, 507
replace() (path module) method, 71, 326, 327–328
repositories (project), 74, 75–76
repr() function, 61
__repr__() method, 168–169, 638
requirements.txt file, 22, 518, 528–529
resolve() (Path module) method, 323
reStructuredText (reST), 540–541
__reversed__() method, 418, 639
__rfloordiv__() method, 174, 641
right shift (») operator, 47, 345
__rlshift__() method, 174, 642
__rmatmul__() method, 174, 641
rmdir() (path module) method, 326
__rmod__() method, 174, 641
__rmul__() method, 174, 641
RobotFramework, 579
root (in path names), 318, 319
__ror__() method, 174, 642
round() function, 48
__round__() method, 171, 638
__rpow__() method, 174, 641
RPython, 627
__rrshift__() method, 174, 643
__rshift__() method, 174, 345, 642
__rsub__() method, 173, 174, 641
RTF (Rich Text Format) file format, 334–335
RTFMaker library, 334
__rtruediv__() method, 174, 641
run() (asyncio module) function, 468
run_until_complete() function, 468
RustPython, 628
S
sandboxing, 537
scientific notation, 45
scope. See also global scope; local scope
about, 100, 117, 681
enclosing, 105
naming conventions, 156–157
resolution order, 105
screaming snake case, 44–45
scripting (field of study), 627
sdist (source distribution), 516, 531
Seaborn, 624
attributes, 155
creating, 151–152, 153, 154
methods, 158–160
properties, 162–166
and code analysis, 571–574
of data, 373–374
seek() method, 298, 302–303, 371
segmentation faults, 570–571
Seitz, Justin, 626
Selenium, 602
self parameter, 64, 152, 682
Sempf, Bill, 185
send() method, 283–285
sequence patterns, 228–229
sequences, 70, 351
and deserialization, 328–332
formats, 375–377
techniques, 373–375
set comprehensions, 278
set mathematics, 221–222
__setattr__() method, 431–433, 643
__setitem__() method, 231, 235, 639
__set_name__() method, 437, 443, 639
setrecursionlimit() (sys module) function, 125
sets, 220–222
setters, 150, 161–163
setup() (setuptools module) function, 526
setup.cfg file, 518, 519, 520–526
setuptools library, 518, 525, 526, 529
setuptools-scm, 521
severity levels, 196, 549, 552–554
functions, 79–80, 81–82
names, 102
shallow copy, 111–113, 117
shared state technique, 487–488
shelve module, 374
shutdown() function, 485
side effects, 108, 120
sign bit, 345
sign flags, 58
signal module, 503
simple statements, 40
Simplified Wrapper and Interface Generator (SWIG), 630
single-dispatch generic functions, 449–452
@singledispatch decorator, 449–450
@singledispatchmethod decorator, 449–450
Single-Responsibility Principle, 181, 196, 382
size= keyword, 300, 301
Skulpt, 623
slice() method, 235
slice notation, 231–236
slicing bytes objects, 361–363
slots
about, 444–445
for immutable classes, 447–449
using, 445–446
__slots__ attribute, 444–446, 646
snake case, 683
Snakeviz, 616–617
Snapcraft, 538
SOLID principles, 382–384
sorted() function, 108, 141, 243–244, 249
source distribution (sdist), 516, 531
special attributes, 426, 644–646, 654
about, 167
binary operator support, 173–174
comparisons, 171–173
conversions, 168–171
making instances callable, 175–176
NotImplemented exceptions, 197
unary operator support, 174–175
Sphinx, 540–541
sprints, 634
Spyder, 36
standard error stream, 290–291, 297
standard input stream, 297, 469
standard output stream, 290, 297
starmap() (itertools module) function, 252
starred expressions, 226–227
starvation, 494
statements, 40–42, 53
states, 120, 180, 181, 190, 684
static analyzers, 29–33, 571
static vs. dynamic typing, 6, 44, 98–99
stderr (standard error) stream, 290–291, 297
stdin (standard input) stream, 297, 469
stdout (standard output) stream, 290, 297
stem (in path names), 318, 319
StopIteration, 200, 240, 261, 264
__str__() method, 169–170, 638
StreamHandler objects, 550, 551
as iterators, 301–302
position in, 302–303
standard, 290–291, 297
types, 295
concatenations, 62
conversions, 61–62
formatted strings (f-strings), 56–60
immutability, 106
and printing, 292–294
string literals, 53–55
strongly typed languages, 44
struct module, 352–357
about, 352–353
creating Struct objects, 356–357
packing to binary, 353–355
unpacking to Python values, 355–356
structural pattern matching, 68–71, 177–180, 228–230
stub classes, 385
style guidelines, 27–29, 31, 33–34, 75
__sub__() method, 173, 174, 640
__subclasscheck__() method, 418, 644
__subclasshook__() method, 644
Sublime Text, 35–36
subpackages, 75
subprocesses
in producer/consumer problem, 503–504, 506–507
and speed considerations, 500–501
subscriptable collections, 231
subscripts. See indices (subscripts)
subtraction (-) operator, 46
suffixes (in path names), 318, 319–320
suffixes (path module) property, 317
suites, 41
superclass linearization, 389–392
Svetlov, Andrew, 468
Sweigart, Al, 622, 627
symlink_to() (path module) method, 326
symmetric difference (^) set operator, 221
SyntaxError, 210
SyntaxWarning, 545
sys module, 291
SystemError, 210
Systems Hungarian Notation, 115–116
T
tab (\t), 293–294
takewhile() (itertools module) function, 252
tan() (math module) function, 48
.tar.gz files, 516, 531
tasks, 466–468
tau constant, 47
tell() method, 302
ternary expressions, 275
test-driven development (TDD), 578
Test PyPI, 532
testing. See also pytest; textproof project example
approaches, 185–186, 577–578
code coverage evaluation, 607–609
with fixtures, 586–588
flaky tests, 591
frameworks, 34, 578–579
GUI and web-based applications, 601–602
with marking, 598
of packages, 530–531, 532, 610–611
with parametrization, 594, 595, 605
unit testing, 583–584
text-based serialization, 373–374
API communication, 588–590
command-line interface, 606–607
connecting API, 602–604
fixtures, 586–588, 595–596
integration testing example, 605
marking, 598–600
pytest installation, 584
skipped test examples, 591–592
Typo initializer, 592–595
thread of execution, 459, 478
about, 459, 477
basic, 478–481
daemonic threads, 782–483
futures and executors, 483–485
and locks, 492–494
race conditions, 487, 488–492
safety, 486–488
timeouts, 481–482, 486
threading module, 478–479, 508
ThreadPoolExecutor object, 484, 491–492
Timecard packaging example, 514, 520–523, 525–526, 532–534
timeouts, 481–482, 486, 506
Tkinter GUI framework, 621
to_bytes() method, 349–351
TOML (TOM's Obvious Minimal Language) file format, 334
tool configurations, 530
TOOWTDI (There's Only One Way To Do It), 7, 10
touch() (path module) method, 326
tox tool, 578, 610–11
tracebacks, 185–186, 186–187
trailing commas, 126, 217, 226
training (machine learning), 625
transpilers, 5
Trio library, 460, 466, 468
True and False values, 51, 237–238, 345
__truediv__() method, 174, 640
__trunc__() method, 171, 638
try clauses, 64–65, 187–188, 189
in collections, 216–218
concatenating, 62
immutability, 106
syntax, 65–66
unpacking, 123
twine, 532
Twisted library, 460
2to3 tool, 7
two's complement, 341, 350–351
type aliases, 146
type() function, 99–100, 404–405
type hints, 145–147
TypeError, 65, 134, 152, 198, 210
U
unary operators, 46, 47, 174–175
underscore (_)
as name, 226, 227
as wildcard, 68
unittest module, 578
Python installer, 15–17
unlink() (path module) method, 326
unordered collections, 220
unpack() (struct module) method, 355–356
from bytes objects to Python values, 355–356
deques, 225–226
dictionaries, 227–228
with starred expressions, 226–227
tuples, 123, 126
UnsupportedOperation, 299
to PyPI, 534
to Test PyPI, 532–533
user groups, 633
V
validation vs. assertion, 558–559
ValueError, 65`, 115, 190, 198, 210
about, 96, 99, 117
coercion and conversion, 114–115
garbage collection of, 100–101
and identity, 97–98
local vs. global references, 101
mutating, 106–107
values() method, 228
van Rossum, Guido, 3, 4, 8, 9, 10
variable annotations, 145–146
variables. See also names; values
about, 96, 117
declaring, 44–45
in f-strings, 56–57
scope, 100, 102–104
variadic arguments, 130–132
vars() function, 428–429
Vaughan, Lee, 625, 627
version control systems (VCS), 19, 23–24, 74
versions, 521, 525
Vim, 34–35
activating, 20
creating, 19
leaving, 20–21
module search paths in, 89–90
using without activating, 26
and VCS repositories, 23–24
virtual machine design patterns, 373
virtual machines, 6
virtual subclasses, 418–422
- (P) data type, 355
W
walrus (: operator, 52–53, 369
Ward framework, 579
warning categories, 545
warning filters, 546–548
converting to exceptions, 548
creating, 544–546
weak references, 106, 117, 446
__weakref__ attribute, 446, 646
web development, 622–623
wheel artifacts (.whl), 516, 531
whence keyword, 302, 371
while loops, 66, 214–215, 245–246
whitespace, 41–42
wildcards, 68, 229–230, 527
paths, 318–319
Python installer, 14
with statement, 297, 307–309
with_name() (path module) method, 327
word size, 355
creating, 491–492
and queues, 495–496
workshops, 634
wrapper modules, 629
wrappers, 144
wraps (functools module) function, 144
writable() method, 299
write() method, 304–305, 307
writelines() method, 305–306, 307
X
XML file format, 333
__xor__() method, 174, 345, 642
Y
Z
Fair Use Sources
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)
© 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.