Index

Please note that index links to approximate location of each term.

Numbers and Symbols

256 objects and 257 objects, 154155

./, using with Ubuntu, 42

/? command line argument, 2526

= assignment operator, 113

== comparison operator, 113, 336

chaining, 105

using to compare objects, 154

using with None, 96

!= comparison operator, 336

* and ** syntax

using to create variadic functions, 167171

using to create wrapper functions, 171172

using with arguments and functions, 166167

* character, using as wildcard, 2829

? character, using as wildcard, 2829

[:] syntax, using, 105

< comparison operator, 337

<= comparison operator, 337

> comparison operator, 337

>= comparison operator, 337

-> (arrow), using with type hints, 191

(backslash)

purpose of, 18

using with strings, 97

: (colon), using with lists, 9899, 105

, (comma), including in single-item tuples, 150

- (dash), using with command line arguments, 25

$ (dollar sign), using in macOS, 23

. (dot), using with commands, 31

-- (double dash), using with command line arguments, 25

__(double underscore), using in dunder methods, 322. See also underscore (_)

/ (forward slash)

purpose of, 18

using with command line arguments, 25

# (hash mark

)

using with comments, 183

using with docstrings, 188

[] (index operator), using, 117

; (semicolons), using with timeit module, 226227

' (single quote), using, 46

~ (tilde), using in macOS, 23

- (unary operator), 155157

+ (unary operator), 156157

_ (underscore)

PEP 8’s naming conventions, 6061

as prefix for methods and attributes, 291292

private prefix, 81

using with _spaces attribute, 290

using with dunder methods, 120

using with private attributes and methods, 283

using with WizCoin class, 279

A

abcTraceback.py program, saving, 4

__abs__() numeric dunder method, 328

absolute versus relative paths, 2021

__add__() numeric dunder method, 327

addToTotal() function, creating, 172173

algebra for big O, 236

algorithm analysis. See big O algorithm

aliases, defined, 121

all() function, 157158

alphabetical sort, performing, 146147

ALT key. See keyboard shortcuts

Amdahl’s Law, 229230

and operator, using, 104

__and__() numeric dunder method, 328

anonymous functions, 174175

answer archive, building with Stack Overflow, 12

antigravity feature, enabling, 160

API (application programming interface), 130

API vs. library vs. framework vs. SDK vs. engine, 130

append() method, using, 115

applications, opening, 22

arguments. See also positional arguments

vs. parameters, 128

passing to functions, 166167

setting defaults for parameters, 142143

arrow (->), using with type hints, 191

ASCII (American Standard Code for Information Interchange), 146

ASCII art, using in Four-in-a-Row game, 272

AsciiArt class, creating, 304305

assignment and comparison operators, chaining, 104105

atoms and literals, 110

attributes

as backing fields, 317318

defined, 278, 282284

vs. properties, 128129

turning into properties, 316319

vs. variable, 124

B

backing field, relationship to attributes, 317318

backporting type hints, 196

backslash ()

purpose of, 18

using with strings, 97

base class, relationship to inheritance, 296

Bash file, 2223

BFG Repo-Cleaner tool, 220

big O algorithm

algebra, 236

algorithm analysis, 230

analysis, 230

analysis examples, 239242

analyzing, 243244

best practice, 244

bookshelf metaphor for orders, 231235

determining order for code, 237244

doing analysis, 236

function calls, 242243

lower and higher orders, 230231

lower orders and coefficients, 238239

math for analysis, 236

measuring worst-case scenario, 235

“n” is small, 244

order of function calls, 242243

orders of notation, 245

big Omega notation, 235

big Theta notation, 235

binary code, explained, 129

Black code formatting tool

adjusting line length setting, 55

described, 45

disabling double-quoted strings setting, 5556

disabling for parts of code, 57

installing, 54

previewing changes, 5657

running from command line, 5457

semantic decisions, 58

syntactic decisions, 58

block vs. clause vs. body, 123124

__bool__() numeric dunder method, 328

Boolean values, 158159. See also values

Bourne Shells, 2223

bugs, types of, 109, 150151

bytecode vs. machine code, 129

C

C: part of path, 18

-c switch, using to run code from command line, 26

callables and first-class objects, 121122

camelCase, 60

casing styles, 60

Catalina version, 23

cd (change directories) command, 2930

__ceil__() numeric dunder method, 328

chaining operators, 105, 159160

child class, creating, 294

class attributes, 306

class methods, 304306

class objects, 284

classes. See also inheritance

creating, 77

creating objects from, 278

creating WizCoin, 279284

defined, 276

designing for real world, 290291

as functions or modules, 77

“is a” relationships, 299

clause vs. block vs. body, 123124

CLI (command line interface), 22

close() and open() functions, 9596

cls and clear (clear terminal) commands, 35

code. See also source code

avoiding guesses, 90

beauty of, 88

commented out, 7475

flat vs. nested, 89

formatting for readability, 1213

implementation, 90

interrupting, 134

namespaces, 91

organizing, 77

readability of, 89

running from command line, 26

silenced errors, 8990

simplicity and complexity of, 89

sparse vs. dense, 89

special cases, 89

speed of, 90

verbose and explicit, 89

code formatting, defined, 45

code point, getting for characters, 146147

code smells. See also source code

classes as functions or modules, 77

commented-out code, 7475

dead code, 7475

defined, 69

duplicate code, 7071

empty except blocks, 7980

error messages, 7980

list comprehensions, 7779

magic numbers, 7173

myths, 8084

print debugging, 7576

summary, 8485

variables with numeric suffixes, 76

codetags and TODO comments, 187

coercion, explained, 128

collections module, contents of, 120

collections.defaultdict, using for default values, 101

colon (:), using with lists, 9899, 105

comma (,), including in single-item tuples, 150

command history, viewing, 28

command line

arguments, 2426

options, 25

overview, 2223, 42

running code with -c switch, 26

running programs from, 2324

running py.exe program, 2627

running Python programs from, 26

tab completion, 2728

terminal window, 23

Command Prompt shell, 23

commands

canceling, 28

cd (change directories), 2930

cls and clear (clear terminal), 35

copy and cp (copy files), 3132

del (delete files and folders), 3334

dir (list folder contents), 30

dir /s (list subfolder contents), 31

find (list subfolder contents), 31

ls (list folder contents), 30

md and mkdir (make folders), 34

move and mv (move files), 32

mv (rename files and folders), 3233

rd and rmdir (delete folders), 3435

ren (rename files and folders), 3233

rm (delete files and folders), 3334

running from Python programs, 27

shortened names, 32

where (find programs), 35

which (find programs), 35

wildcard characters, 2829

commented-out code, 7475

comments

best practices, 197

myth about, 8384

using, 182188

using with type hints, 196

commit history, rewriting in Git, 220

commit log, viewing in Git, 216217

commits, rolling back in Git, 218220

comparing objects, 154155

comparison operators. See also sequence comparisons

chaining with assignment operators, 104105

function form of, 333

comparisons, making, 96

__complex__() numeric dunder method, 328

composition vs. inheritance, 299301

conditional expressions, ternary operator, 102104

containers, defined, 119120

Cookiecutter, using to create projects, 200202

copy and cp commands, 31

copy.copy() and copy.deepcopy(), using with mutable values, 140142

copying

files and folders, 31

mutable values, 140142

cProfile profiler, 154, 228230

CPU, instruction set of, 129

CPython implementation, 108

CTRL key. See keyboard shortcuts

cwd (current working directory), 1920, 31

D

dash (-) using with command line arguments, 25

data, validating with setters, 319

data types

defined, 276

and return values, 177178

dead code, 7475

decimal.Decimal(), passing integers to, 148149

decrement and increment operators, 156157

default arguments, setting for parameters, 142143, 165166

default values, using collections.defaultdict for, 101

deleting

files and folders, 3334

files from repo, 214215

folders, 3435

items from list, 134140

and moving files in repo, 215216

derived class, relationship to inheritance, 296

deterministic function, 173. See also functions

dictionaries

get() and setdefault() methods, 105

key-value pairs, 118

Python mailing list discussion, 131

setting type hints for, 195196

using, 99102

using as default arguments, 143144

diff program, seeing changes with, 211212

dir command, using, 30

dir /s command, 31

displays and literals, 110

__divmod__() numeric dunder method, 327

docs folder, contents of, 200

docstrings

defined, 182

summary, 197

using, 188190

dollar sign ($), using in macOS, 23

doskey program, 28

dot (.), using with commands, 31

double dash (--), using with command line arguments, 25

double-free bugs, 109

double underscore (__), using in dunder methods, 322. See also underscore (_)

dunder methods. See also methods; OOP (object-oriented programming)

comparison, 332337

defined, 120

numeric, 325328

in-place augmented assignment, 330332

reflected numeric, 328330

string representation, 323325

using, 322323

duplicate code, 7071

dynamic typing, 190

E

Easter egg, The Zen of Python as, 88

encapsulation, explained, 307308

encoding definition, using with magic comment, 187188

engine vs. library vs. framework vs. SDK vs. API, 130

enumerate() vs. range(), 9495, 105105

environment setup, process of, 17, 42

environment variables and PATH, 3539

__eq__() comparison dunder method, 336

EQual operation, 336

equality (==) operator, using with None, 96

error codes, returning, 178179

error messages

and except blocks, 7980

getting help with, 11

parsing, 15

tracing, 178

understanding, 48

errors, preventing with linters, 89

exceptions

catching, 7980

raising, 4, 105, 178179

RecursionError, 318319

explanatory comments, 184185

expressions vs. statements, 122123

F

False and True keywords, 158159

FAQs (Frequently Asked Questions), 10

filenames, as command line arguments, 25

filenames and folders, matching with wildcards, 2829

file paths, specifying, 2021

files

copying, 31

deleting, 3334

moving, 32

renaming, 3233

filesystem, 1821, 42

filtering with list comprehensions, 175176

find command, 31

find feature, accessing, 64, 67

find() string method, error related to, 178

finding programs, 35

first-class objects and callables, 121122. See also objects

flag arguments, myth about, 82

__float__() numeric dunder method, 328

floating-point numbers, accuracy of, 147149, 151

__floor__() numeric dunder method, 328

__floordiv__() numeric dunder method, 327

folders

adding to PATH on macOS and Linux, 39

adding to PATH on Windows, 3839

as command line arguments, 25

copying, 31

deleting, 3334

in filesystem, 18

home directory, 19

listing contents of, 30

making, 34

moving, 32

renaming, 3233

folders and filenames, matching with wildcards, 2829

for expressions, including in list comprehension, 79

for loops

in big O analysis, 240

getting index and value, 105105

and lists, 134140

versatility of, 125

form, filling out, 276278

format() string method, 9798

formatting for readability, 58

formatting strings, 9698

forward slash (/)

purpose of, 18

using with command line arguments, 25

Four-in-a-Row tile-dropping game

output, 259260

source code, 260264

summary, 271272

writing code, 264271

frame object, explained, 5

frame summary, explained, 5

framework vs. library vs. SDK vs. engine vs. API, 130

f-strings, formatting strings with, 9798

functional programming

higher-order functions, 174

lambda functions, 174175

list comprehensions, 175176

mapping and filtering, 175176

side effects, 172174

function calls, order in big O, 242243

functions. See also deterministic function; higher-order functions; nondeterministic function; pure function; variadic functions; wrapper functions

default arguments, 165166

vs. methods, 82, 124

names, 162

parameters and arguments, 165172

passing arguments to, 166167

and return statements, 8081

size trade-offs, 162165

and try statements, 8182

using default arguments with, 142143

G

garbage collection, 109, 226

__ge__() comparison dunder method, 337

get(), using with dictionaries, 99101

getPlayerMove() function, 163165

getters and setters, 315, 318

Git. See also repo

adding files to track, 208209

command line tool, 207

commits and repos, 200, 206207

committed state, 204

committing changes, 210214

configuring username and email, 203

deleting files from repo, 214215

as distributed version control system, 206

frequency of committing changes, 213214

ignoring files in repo, 209210

installing, 202204

keeping track of file status, 204206

log command, 216217

modified state, 204

recovering old changes, 217220

renaming and moving files in repo, 215216

rewriting commit history, 220

running status with watch command, 207

staged state, 205206

storing private information in, 220

viewing changes before committing, 211212

viewing commit log, 216217

workflow, 204206

git add command, 223

git clone command, 223

git commit command, 223

git diff, using, 211213

git filter-branch command, 220

git init command, 223

GitHub and git push command, 221223

glob patterns, explained, 29

global variables, myth about, 8283

glossary, accessing, 108, 131

GrandchildClass, creating, 294295

Greater Than operation, 337

Greater than or Equal operation, 337

__gt__() comparison dunder method, 337

GUI (graphical user interface), 22

GUI Git tools, installing, 203204

H

hash mark (#)

using with comments, 183

using with docstrings, 188

hashes, defined, 117119

--help command line argument, 2526

help with programming, asking for, 914

higher-order functions, 174. See also functions

home directory, 19

Homebrew, installing and configuring, 213

horizontal spacing, 4751

Hungarian notation, 63

I

id() function, calling, 111, 154

identifiers, defined, 59

identities, defined, 111114

IEEE 754 standard and floating-point numbers, 147148

if statement as clause header, 124

immutable and mutable objects, 114117, 144

in operator, using with values of variables, 105

increment and decrement operators, 156157

indentation, using space characters for, 4748. See also significant indentation

index operator ([]), using, 117118

index() string method, exception related to, 179

indexes, defined, 117119

inequality != operators, avoiding chaining, 149150

inheritance. See also classes; multiple inheritance; OOP (object-oriented programming)

base classes, 296

best practice, 308309

class attributes, 306307

class methods, 304306

vs. composition, 299301

creating child classes, 294

derived classes, 296

downside, 301303

explained, 293

isinstance() and issubclass() functions, 303304

MRO (method resolution order), 310312

overriding methods, 296297

static methods, 306307

subclasses, 296

super classes, 296

super() function, 297299

__init__(), and self, 280282

__init__.py file and packages, 121

inline comments, 183184

in-place augmented assignment dunder methods, 330332

installing

Black code formatting tool, 54

Git, 202204

Homebrew, 213

Meld for Linux, 213

Mypy, 192193

Pyflakes, 9

tkdiff, 213

instances, defined, 111114, 276. See also isinstance()

instruction set, explained, 129

int() function, using, 158

__int__() numeric dunder method, 328

integers, passing to decimal.Decimal(), 148149.

__invert__() numeric dunder method, 328

“is a” relationships for classes, 299

is operator, using, 113

isinstance(). See also instances

and issubclass() functions, 303304, 312

using with Boolean values, 158

items

best practices for dealing with, 134140

defined, 114

iterable unpacking, using to swap variables, 227

iterable vs. iterator, 125126

iterating

explained, 134

forward and backward, 139

J

JDK (Java Development Kit), 130

join() operator, using with strings, 151

JVM (Java Virtual Machine), 129

K

keyboard shortcuts

canceling commands, 28

find feature, 64, 67

interrupting code, 134

interrupting infinite loops, 134

opening applications, 22

opening terminal window, 23, 41

Task Manager, 22

viewing running processes, 22

keys, defined, 117119

keywords

arguments, 167

defined, 110111

True and False, 158159

Kompare, using, 213

L

lambda functions, 174175. See also functions

__le__() comparison dunder method, 337

legal comments, 186

len() function, using, 94

Less Than operation, 337

Less than or Equal operation, 337

“lessons learned” comments, 185186

library vs. framework vs. SDK vs. engine vs. API, 130. See also Python Standard Library

LICENSE.txt file, 200

links to URLs, including in comments, 183

linters, preventing errors with, 89, 15

Linux

installing Meld for, 213

running Python programs on, 41

list comprehensions

and all() function, 157

mapping and filtering with, 175176

using, 7779, 137

list concatenation, 115

lists

adding or deleting items from, 134140

best practices for dealing with, 134140

contents of, 141142

making shallow copies of, 9899

setting type hints for, 195196

using as default arguments, 143144

literals, defined, 109110

logfiles, setting up, 7576

logical error, defined, 127

looping, explained, 134

loops

interrupting, 134

moving duplicate code into, 71

ls command, using, 30

__lshift__() numeric dunder method, 328

__lt__() comparison dunder method, 337

M

machine code vs. bytecode, 129

macOS

installing tkdiff, 213

running Python programs on, 41

magic comments and source file encoding, 187188

magic methods, defined, 120

magic numbers, 7173

main() function, changing to override methods, 296297

mapping. See also objects

defined, 119120

and filtering with list comprehensions, 175176

mapping data types, passing, 167

math dunder methods, 325328

__matmul__() numeric dunder method, 327

max() and min() functions, 169

MCR (minimum, complete, reproducible) example, 11

md and mkdir commands, 34

Meld, installing for Linux, 213

memory leaks, 109

memory usage, 137138

metasyntactic variables, 60. See also variables

methods. See also dunder methods; private attributes and private methods

vs. functions, 82, 124

__init__(), and self, 280282

overriding, 296297

min() and max() functions, 169

__mod__() numeric dunder method, 327

modules

defined, 120121

finding, 14

and packages, 120121

requests, 188189

typing, 195196

move and mv (move files) commands, 32

moving files and folders, 32

MRO (method resolution order), 310312

__mul__() numeric dunder method, 327

multiple assignment trick, using to swap variables, 227

multiple inheritance, 309310. See also inheritance

mutable and immutable objects, 114117, 151

mutable values

best practices for dealing with, 142144

copying, 140144

and default arguments, 142144

Mypy, using, 192194

N

name length, considering, 6164

nameless functions, 174175

names.

advice about, 6465

avoiding overwriting, 6566

choosing, 67

making searchable, 64

prefixes in, 6364

sequential numeric suffixes in, 64

namespaces, 9091

__ne__() comparison dunder method, 336

__neg__() numeric dunder method, 328

nested conditional expressions, 104

nested loops, using in big O analysis, 241

next() function, calling, 126

no operation, explained, 74

nondeterministic function, 173. See also functions

None, using == (equality) operator with, 96

Not Equal operation, 336

NotImplementedError, raising, 75

numbers, magic, 7173.

numeric dunder methods, 325328

O

O(1), Constant time, 231232

objects. See also mapping

and classes, 276

comparing, 154155, 334

creating from classes, 278

defined, 111114

mutable and immutable, 114117

sorting, 336

O(log n), Logarithmic, 232

O(n!), Factorial Time, 234235

O(n), Linear Time, 232

O(n log n), N-Log-N Time, 232233

O(n2), Polynomial Time, 233

O(n11), Exponential Time, 233234

OOP (object-oriented programming). See also dunder methods; inheritance

creating objects from classes, 278

defined, 275

designing classes, 290291

encapsulation, 307308

filling out form, 276278

and non-OOP examples, 285290

polymorphism, 308

properties, 316322

summary, 292

tic-tac-toe, 285290

type() function and __qualname__attribute, 284285

using class and static features, 307

WizCoin class, 279284

open()

and close() functions, 9596

and readlines() functions, 126

operator module, 333, 336337

operators, chaining, 105, 151, 159160

optimizations

preallocated integers, 154

string interning, 155

__or__() numeric dunder method, 328

ordinal, getting for characters, 146147

os.chdir(), using, 20

P

packages

defined, 120121

and modules, 120121

parameters vs. arguments, 128

ParentClass, creating, 294295

PascalCase, 60

pass statement

relationship to stubs, 7475

using with except block, 7980

PATH and environment variables, 3539

pathlib module, importing, 1819

paths, specifying, 1821

p-code, explained, 129

PEP (Python Enhancement Proposal) 8

documentation, 67

naming conventions, 61

and style guides, 4647

performance, measuring, 9294

Perl programming language, 90

pip list, running, 14

polymorphism, explained, 308

portable code, explained, 129

porting vs. backporting, 196

__pos__() numeric dunder method, 328

positional arguments, defined, 166167. See also arguments

__pow__() numeric dunder method, 328

practice projects. See also projects

Four-in-a-Row, 259271

The Tower of Hanoi, 248259

preallocated integers, 154.

premature optimization, 92, 226

print debugging, 7576

print() function

arguments for, 168

passing list to, 166

using with wrapper functions, 171

private attributes and private methods, 282284. See also methods

processes and programs, 2122

professional comments, 186

profiling, explained, 92, 228

program vs. script, 129130

programming help, asking for, 914

programming language vs. scripting language, 129130

programs. See also Python programs

finding, 35

and processes, 2122

running from command line, 2324, 26

running without command line, 3942

vs. scripts, 129130

project folder, contents of, 200

projects, creating with Cookiecutter, 200202. See also practice projects

properties

vs. attributes, 128129

best practices, 322

read-only, 320321

turning attributes into, 316319

using, 316

public access attributes and methods, 283

pure function, 173174. See also functions

push command, using in Git, 221223

.py source code files, locating, 200

.pyc files, bytecode in, 129

py.exe program, running, 2627

Pyflakes, installing, 9

PyPy just-in-time compiler, 108

Python

documentation, 121

error messages, 48

glossary, 108, 131

language and interpreter, 108109

programming language, 109

Python programs, running without command line, 3942. See also programs; The Zen of Python

Python Standard Library, 120121. See also library vs. framework vs. SDK vs. engine vs. API

pythonic code, core of, 105

Q

__qualname__attribute and type() function, 284285

questions, asking, 1011, 1415

R

__radd__() reflected numeric dunder method, 330

raising exceptions, 178179

__rand__() reflected numeric dunder method, 330

range() vs. enumerate(), 9495, 105105

rd and rmdir commands, 3435

__rdivmod__() reflected numeric dunder method, 330

readlines() and open() functions, using, 126

README files, 200, 211212, 215216, 218

read-only properties, 320321

RecursionError exception, raising, 318319

references, explained, 137138

reflected numeric dunder methods, 328330

relative vs. absolute paths, 2021

renaming files and folders, 3233

repo. See also Git

cloning for GitHub repo, 222223

creating, 223

creating on computer, 206207

deleting and moving files in, 215216

deleting files from, 214215

ignoring files in, 209210

and version control systems, 200

__repr__() method, using, 325

repr string, sensitive information in, 325

requests module, sessions.py file, 188189

return values and data types, 177178. See also values

__rfloordiv__() reflected numeric dunder method, 330

__rlshift__() reflected numeric dunder method, 330

rm (removing files and folders) command, 3334

__rmatmul__() reflected numeric dunder method, 330

__rmod__() reflected numeric dunder method, 330

__rmul__() reflected numeric dunder method, 330

roll back, performing in Git, 217220

root folder, explained, 18

__ror__() reflected numeric dunder method, 330

__round__() numeric dunder method, 328

__rpow__() reflected numeric dunder method, 330

__rrshift__() reflected numeric dunder method, 330

__rshift__() numeric dunder method, 328

__rsub__() reflected numeric dunder method, 330

__rtruediv__() reflected numeric dunder method, 330

running processes, viewing, 22

runtime

defined, 226

quickening for functions, 173

vs. syntax vs. semantic errors, 126127

__rxor__() reflected numeric dunder method, 330

S

%s conversion specifiers, using, 98

script vs. program, 129130

scripting language vs. programming language, 129130

SDK vs. library vs. framework vs. engine vs. API, 130

self and __init__(), 280282

semantic vs. syntax vs. runtime errors, 126127

semicolons (;), using with timeit module, 227

sensitive information in repr strings, 325

sequence comparisons, 335336. See also comparison operators

sequences

defined, 119120

and iterables, 125

sessions.py file in requests module, 188189

set types, defined, 119120

setdefault(), using with dictionaries, 99101

setters

and getters, 315, 318

using to validate data, 319320

sh file, 2223

shell programs, 2223

side effects, 172174

significant indentation, 9192, 105. See also indentation

single quote ('), using, 46

slice syntax, explained, 98

snake_case, 60

snapshots, saving with Git, 200

software license, file for, 200

sort() function, behavior of, 146147, 151, 332, 336

source code, avoiding dropping letters from, 62. See also code; code smells

source file encoding and magic comments, 187188

space characters, rendering on screen, 47

spacing within lines, 4851

Stack Overflow, building answer archive, 12

stack trace, 47

staged files

committing, 211

unstaging in Git, 218

statements vs. expressions, 122123

static analysis, explained, 8, 192194

static methods, 306307

string concatenation, 144146, 151

string interning, 155156

strings

formatting, 9698

as immutable objects, 144

immutable quality of, 116

interpolating, 105

stubs, relationship to code smells, 74

style guides and PEP (Python Enhancement Proposal) 8, 4647

__sub__() numeric dunder method, 327

subclass, relationship to inheritance, 296. See also isinstance()

subfolders, listing contents of, 31

Sublime Text editor, 193

subprocess.run() function, 27

subtract() function, creating, 172

sum() function, 168

summary comments, 185

super class, relationship to inheritance, 296

super() function, relationship to overriding method, 297299

switch statement vs. dictionaries, 101102

syntax

catching errors, 6

misuse of, 9496

vs. runtime vs. semantic errors, 58, 126127

sys.getsizeof() function, 137138

system environment variables, 38

T

tab completion, 2728

Task Manager, opening, 22

terminal window

clearing, 35

opening, 23, 41

ternary operator, 102104

tests folder, contents of, 200

text editor, Sublime Text, 193

tic-tac-toe program

creating, 285290

MRO (method resolution order), 311312

tilde (~), using in macOS, 23

timeit module, using to measure performance, 9294, 105, 226228. See also modules

time.time() function, 72, 93

tkdiff, installing on macOS, 213

TODO comments and codetags, 187

The Tower of Hanoi puzzle

getPlayerMove() function, 163, 165, 254257, 268

output, 249250

restrictions, 248

source code, 250252

summary, 271272

writing code, 252259

tracebacks, examining, 47

True and False keywords, 158159

__truediv__() numeric dunder method, 327

__trunc__() numeric dunder method, 328

tuples

identities, 119

immutable quality of, 116117

using commas with, 150

values of, 116

type coercion vs. type casting, 128

type() function and __qualname__attribute, 284285

type hints, 182, 190196

types, defined, 276

typing, minimizing with tab completion, 2728

typing module, 195196

U

Ubuntu Linux, running Python programs on, 4142

underscore (_). See also double underscore (__)

PEP 8’s naming conventions, 6061

as prefix for methods and attributes, 291292

private prefix, 81

using with _spaces attribute, 290

using with dunder methods, 120

using with private attributes and methods, 283

using with WizCoin class, 279

undo features, 199, 217220

Unicode resource, 188

unit tests, folder for, 200

Unix operating system, shell programs, 2223

URL links, including in comments, 183

user environment variables, 38

UTF-8 encoding, 187188

V

validating data using setters, 319320

values. See also Boolean values; return values and data types

defined, 111114

modifying in place, 115

variable names, 64, 66. See also names

variable values, 104105

variables. See also metasyntactic variables

vs. attributes, 124

box vs. label metaphor, 112113

checking values, 105

with numeric suffixes, 76

swapping, 227

variadic functions, creating, 167171. See also functions

version control systems, 199200

vertical spacing, 5153

volumes, explained, 18

W

watch command, using with Git, 207

webbrowser module, 160

where command, 35

which command, 35

while keyword, 110

while loops

in big O analysis, 241

and lists, 134140

wildcard characters, 2829

Windows, running Python programs on, 4041

WinMerge, downloading, 212213

with statement, 9596

WizCoin class, creating, 279284

worst-case scenario, measuring with Big O, 235

wrapper functions, creating, 171172. See also functions

X

XOR algorithm, using, 92, 226227

__xor__() numeric dunder method, 328

Z

Zakharenko, Nina, 131

The Zen of Python, 8891. See also programs; Python programs

zero-based indexing, using, 117

Zsh and Z shells, 23

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.67.26