A
a
mode, 96
a +
mode, 96
abs()
function, 166, 168
- accessing
- contents of imported modules, 45
- data in lists, 244–245
- adding
- comments to code, 42–43
else
blocks, 225, 229
finally
blocks, 225, 229
- items
- to lists, 240–241
- to tuples, 65
- key/value pairs to dictionaries, 254–255
- adjusting
- order of operations, 113
- order of precedence using parentheses, 115
- string capitalization, 200–203
aiter()
function, 168
- algorithms, 4
- alias, importing modules/objects under an, 46
all()
function, 168
- American Standard Code for Information Interchange (ASCII), 183
AND
(&) operator, 120, 126
anext()
function, 168
any()
function, 168
- Append and Read Mode, 96, 107
append()
method, 239, 240–241
- Append Mode, 96
- appending data to files, 106–107
- applying themes, 22–23
- Arch, 15
- arithmetic operators, 112–115
- arrays, compared to lists, 237
- ASCII (American Standard Code for Information Interchange), 183
ascii()
function, 168
AssertionError
, 222
- assigning values to variables, 53
- assignment operators, 116–117
- Atom, 19
AttributeError
, 222
- Auto Save feature (Visual Studio Code), 33
- auto saving, in Visual Studio Code, 27
- AutoComplete list, 35
B
- backslash, 83, 185
basename()
method, 95
bin()
function, 168, 170, 171
- binary strings, 171
- bitwise operators, 126–127
bool()
function, 62–63, 74, 75, 168
- Boolean values, 62–63
- braces ({}), 206–207, 212–213, 217, 248, 250
break
statement, 145, 149, 151, 154, 155
breakpoint()
function, 168
- build types, 7
- built-in functions, 168–171
- byte code, 220
bytearray()
function, 168
bytes()
function, 168
C
- C programming language, 54
callable()
function, 168
- calling
- class methods, 272
- instance methods, 271
- static methods, 273
- capitalization
- of classes, 263
- of strings, 200–203
capitalize()
method, 188
- carriage-return characters, creating multiline strings using, 187
casefold()
method, 188, 203
center()
method, 188, 189
- changing
- order of operations, 113
- order of precedence using parentheses, 115
- string capitalization, 200–203
- character codes, 183
- character sets, 183
chdir()
method, 82–83, 92
- child directory, 78
chr()
function, 75, 168
- class attributes
- about, 266–267
- returning, 269
- setting, 268–269
- class methods
- classes and instances
- about, 57, 262
- class attributes, 266–269
- class methods, 270–273
- code for classes, 277
- creating
- class methods, 275
- classes, 262, 264–265
- instance methods, 274
- static methods, 276
- instance attributes, 266–267
- instance methods, 270–273
- instantiating instances, 264–265
- setting class and instance attributes, 268–269
- static methods, 270–273
classmethod()
function, 168, 272, 275
- cleaning up strings, 192–193
clear()
method, 239, 242–243, 251, 256
close()
method, 97, 100–101
- closing files manually, 97
cm2cf()
method, 276
- code editors
- about, 16
- compared with integrated development environments (IDEs), 17
- entering comments in, 41
- examples of, 19
- recommended, 19
- coding
- adding comments to code, 42–43
- for classes, 277
- commenting out the code, 41
- comments, 40–43
- creating scripts in Visual Studio Code, 32–33
- executing commands in Terminal window, 38
- importing modules/objects, 44–49
main()
function, 30–31
- methods of modules, 48–49
- repetitive code, 37
- running
- code in Visual Studio Code, 34–37
- scripts in Terminal window, 39
- saving scripts in Visual Studio Code, 32–33
- writing code in Visual Studio Code, 34–37
- collections, displaying, 73
- colon (:), 131, 164
- command line, launching scripts via, 31
- commenting out the code, 41
- comments, 40–43
- comparison operators, 118–119
compile()
function, 168
- compile-time errors, 220
complex()
function, 75, 168
- computing platform, 4
- concatenating
- integers, 197
- strings, 196–197
- configuring Visual Studio Code, 26–27
- (continuation) character, 40
continue
statement, 145, 156–157
- continuing loops, 145
- converting
- binary strings to decimal values, 171
- data types, 74–75
- hexadecimal strings to decimal values, 171
- octal strings to decimal values, 171
copy()
method, 90, 239, 251, 253
- copying files and directories, 88–91
copytree()
method, 90
count()
method, 188, 190, 239, 244–245
- creating
- class methods, 272, 275
- classes, 262, 264–265
- comments using # character, 40
- custom exceptions, 232–233
- dictionaries
- about, 250
- from existing iterables, 252–253
- directories, 84–87
- empty tuples, 65
- functions
- with no parameters and no returns, 176
- with no parameters but returns, 174–175
- with optional parameters, 178–179
- with parameters and returns, 172
- with parameters but no returns, 173
- that return multiple values, 177
if
statements, 133
if…elif
statements, 137
if…elif…else
statements, 139
if…else
statements, 135
- instance methods, 271, 274
- instances of classes, 263
- lists, 238
for
loops, 148–149
- multiline strings, 186–187
- nested
if
statements, 141
- nested
try…except
blocks, 230–231
- numeric
for
loops using range()
function, 147
- scripts
- about, 58–59
- in Visual Studio Code, 32–33
- sets with contents, 67
- single-line strings, 184–185
- static methods, 273, 276
- strings
- about, 182, 204–209
- using
.format
method, 212–213
- using f-strings, 214–215
- using interpolation operator, 210–211
- using template strings, 216–217
- variables, 53
while
loops, 152–153
- cross-platform programming, 4
D
- data
- appending to files, 106–107
- writing to files, 102–103
- Data section, in files, 79
- data types
- about, 54–55
- converting, 74–75
- for default values, 179
- exception, 57
- instance, 57
- mapping, 56
- numeric, 54–55
- sequence, 55
- set, 56
day_of_week()
function, 167
- Debian-based distributions, 15
- decimal values, converting binary, octal, or hexadecimal strings to, 171
- deduplicate, 243
def
keyword, 164, 165
- default values, data types for, 179
- definite iteration, using
for
loops for, 144
delattr()
function, 168
- deleting directories, 84–87
- development build, 7
- development tools, for Python, 16–19
dict
data type, 56
dict()
function, 75, 168
- dictionaries
- about, 248–249
- adding key/value pairs to, 254–255
- creating
- about, 250
- from existing iterables, 252–253
for
loops that iterate through, 149
- formatting strings with, 209
- methods for, 251
- removing key/value pairs from, 256–257
- returning
- keys and values from, 258–259
- values, 250
dir()
function, 47, 168
- directories. see files and directories
- directories and files
- about, 78–79
- appending data to files, 106–107
- checking file status, 100–101
- closing files, 97,100–101
- copying, 88–91
- creating
- directories, 84–87
- files, 98–99
- deleting directories, 84–87
- file structure, 79
- listing, 80–81
- loading
os
module, 80–81
- modules for working with, 79
- moving, 88–91
- navigating directories, 82–83
open()
function, 96
- opening files
- about, 98–99
- for reading and writing, 104–105
- reading text files, 108–109
- renaming, 88–91
- splitting file paths, 94–95
- system information, 92–93
- user information, 92–93
- writing data to files, 102–103
- directory path, 78
dirname()
method, 95
- disabling path length limit, 11
- displaying
- collections, 73
- information using
print()
function, 171
- distributions, 4
- division (/) operator, 115
divmod()
function, 168
- domain-specific programming language, 4
- double quotes, 69
- downloading
- Python on Windows, 8–11
- Visual Studio Code, 20–21
- duplicate values, 236
- dynamic typing, 52
E
- elements, 66
else
blocks, adding, 225, 229
else
statements, in loops, 158–159
encode()
method, 188, 189
- ending
for
loops, 149
- End-of-file marker, in files, 79
endswith()
method, 188, 190
- engineers, as Python users, 5
- entering
- comments in code editors, 41
- comments in IDEs, 41
- comments in Terminal windows, 41
enumerate()
function, 168
- environment variables, returning information using, 93
EOFError
, 222
- equal to (==) operator, 118
- error handling
- adding
else
blocks, 229
finally
blocks, 229
- causing errors, 226–227
- creating
- custom exceptions, 232–233
- nested
try…except
blocks, 230–231
- error types, 220–221
- identifying common errors, 222–223
- raising exceptions manually, 228
- trapping exceptions, 226–227
try…except
block, 224–225
- escape character, 83
eval()
function, 168
- exception data type, 57
- exceptions
- creating custom, 232–233
- raising manually, 228
- trapping, 225, 226–227
exec()
function, 168
- exiting loops early using
break
statements, 155
expandtabs()
method, 189
expanduser()
method, 82–83, 92
- explicit conversion, 74
extend()
method, 239, 240–241
- extensions, for Visual Studio Code, 24–25
F
- Fedora, 15
- file paths, splitting, 94–95
FileExistsError
error, 85
- files and directories
- about, 78–79
- appending data to files, 106–107
- checking file status, 100–101
- closing files, 97,100–101
- copying, 88–91
- creating
- directories, 84–87
- files, 98–99
- deleting directories, 84–87
- file structure, 79
- listing, 80–81
- loading
os
module, 80–81
- modules for working with, 79
- moving, 88–91
- navigating directories, 82–83
open()
function, 96
- opening files
- about, 98–99
- for reading and writing, 104–105
- reading text files, 108–109
- renaming, 88–91
- splitting file paths, 94–95
- system information, 92–93
- user information, 92–93
- writing data to files, 102–103
filter()
function, 168
finally
blocks, adding, 229
find()
method, 188, 189, 198–199
float
data type, 54
float()
function, 75, 168
- floating-point numbers
- storing, 54
- troubleshooting, 115
- working with, 60–61
FloatingPointError
, 222
- floor division, 112
- folder path, 78
- folders. see files and directories
for
loops
- creating, 148–149
- ending, 149
- how they work, 146–147
- using for definite iteration, 144
format()
method, 168, 188, 189
.format
method
- building strings using, 212–213
- formatting strings using, 206–207
format_map()
method, 189
- formatting
- strings, 204–205
- strings using
.format
method, 206–207
- strings using f-strings, 207–209
- strings using template strings, 209
from…import
statement, 44
fromkeys()
method, 251, 252–253
frozenset()
function, 169
- f-strings
- about, 204
- building strings using, 214–215
- formatting strings using, 207–209
function_description
, 164
function_name
, 164
- functions
abs()
, 166, 168
aiter()
, 168
all()
, 168
anext()
, 168
any()
, 168
ascii()
, 168
bin()
, 168, 170, 171
bool()
, 62–63, 74, 75,168
breakpoint()
, 168
- built-in, 168–171
bytearray()
, 168
bytes()
, 168
callable()
, 168
chr()
, 75,168
classmethod()
, 168, 272, 275
compile()
, 168
complex()
, 75,168
- creating
- with no parameters and no return, 176
- with no parameters but a return, 174–175
- with optional parameters, 178–179
- with parameters and returns, 172
- with parameters but no returns, 173
- that returns multiple values, 177
day_of_week()
, 167
delattr()
, 168
dict()
, 75,168
dir()
, 47, 168
divmod()
, 168
enumerate()
, 168
eval()
, 168
exec()
, 168
filter()
, 168
float()
, 75,168
frozenset()
, 169
getattr()
, 169
globals()
, 167, 169
hasattr()
, 169
hash()
, 169
help()
, 169
hex()
, 75,169, 170, 171
id()
, 122, 123, 169
input()
, 58–59, 164, 169, 170
int()
, 58–59, 74, 75,115, 169, 171
isinstance()
, 169
issubclass()
, 169
iter()
, 169
len()
, 169, 191
list()
, 75,169, 170
locals()
, 169
main()
, 30–31
make_title()
, 201–202
map()
, 169
max()
, 169
memoryview()
, 169
min()
, 169
mkdir()
, 84–87
next()
, 169
object()
, 169
oct()
, 75,169, 170, 171
open()
, 79, 96–109, 169, 170
ord()
, 75,170
- parameters and returns, 166–167
pow()
, 170
print()
, 53, 58–59, 150, 154, 164, 167, 170, 171, 277
property()
, 170
range()
, 147, 170
repr()
, 170
reversed()
, 170
round()
, 170
set()
, 67, 75,170
setattr()
, 168, 170
slice()
, 170
sorted()
, 170, 171
staticmethod()
, 170, 276
str()
, 68–69, 75,170
sum()
, 170
super()
, 170
- syntax, 164–165
tuple()
, 75,170
type()
, 170
zip()
, 170
G
- general-purpose programming language, 4
- generating
- class methods, 272, 275
- classes, 262, 264–265
- comments using # character, 40
- custom exceptions, 232–233
- dictionaries
- about, 250
- from existing iterables, 252–253
- directories, 84–87
- empty tuples, 65
- functions
- with no parameters and no returns, 176
- with no parameters but returns, 174–175
- with optional parameters, 178–179
- with parameters and returns, 172
- with parameters but no returns, 173
- that return multiple values, 177
if
statements, 133
if…elif
statements, 137
if…elif…else
statements, 139
if…else
statements, 135
- instance methods, 271, 274
- instances of classes, 263
- lists, 238
for
loops, 148–149
- multiline strings, 186–187
- nested
if
statements, 141
- nested
try…except
blocks, 230–231
- numeric
for
loops using range()
function, 147
- scripts
- about, 58–59
- in Visual Studio Code, 32–33
- sets with contents, 67
- single-line strings, 184–185
- static methods, 273, 276
- strings
- about, 182, 204–209
- using
.format
method, 212–213
- using f-strings, 214–215
- using interpolation operator, 210–211
- using template strings, 216–217
- variables, 53
while
loops, 152–153
GeneratorExit
, 222
get()
method, 251
getattr()
function, 169
getcwd()
method, 80
getInfo()
method, 274, 277
getpass
module, 92
- Getting Started screen (Visual Studio Code), 23
getuser()
method, 92
glob()
method, 80
glob
(Global) module, 79
globals()
function, 167, 169
- greater than (>) operator, 118
- greater than or equal to (>=) operator, 118
H
hasattr()
function, 169
hash()
function, 169
- Header section, in files, 79
help()
function, 169
hex()
function, 75, 169, 170, 171
- hexadecimal strings
- converting to decimal values, 171
- returning, 171
- high-level programming language, 54
- home directory, returning, 92
HOME
variable, 93
I
id()
function, 122, 123, 169
- identity operators, 122–123
- IDLE app, 9, 18
if
statements
- about, 30–31, 130–132
- creating, 133
if…elif
statement, 136–137
if…elif…else
statement, 138–139
if…else
statement, 134–135
- nested, 140–141
if…elif
statement, 130, 136–137
if…elif…else
statement, 130, 138–139
if…else
statement, 130, 134–135
- immutable data, 55
- implicit conversion, 74
import
statement, 44, 79
import sys
command, 81
ImportError
, 222
- importing
- modules, 44–48
- objects, 44–48
- scripts, 31
in
operator, 124
- indefinite iteration, using
while
loops for, 144–145
IndentationError
, 223
index()
method, 189, 198–199, 239, 244–245
- indexed lists, 236
IndexError
, 222
- infinite loops, 151
- infinite
while
loops, 153
input()
function, 58–59, 164, 169, 170
insert()
method, 239
- installing
- Python
- on Linux, 14–15
- on Macs, 12–13
- on Windows, 8–11
- Visual Studio Code
- about, 20–21
- extensions for, 24–25
- on Linux, 21
- on macOS, 21
- instance attributes
- about, 266–267
- setting, 268–269
- instance data type, 57
- instance methods
- instances. see classes and instances
- instantiating instances, 264–265
int
data type, 54
int()
function, 58–59, 74, 75, 115, 169, 171
- integer division, 112
- integers
- concatenating, 197
- storing, 54
- working with, 58–59
- integrated development environments (IDEs)
- about, 9, 17
- compared with code editors, 17
- entering comments in, 41
- examples of, 18
- recommended, 19
- Interactive Interpreter, importing scripts into, 31
- interpolation operator
- building strings using, 210–211
- formatting strings using, 204–205
- interrupting
- infinite
while
loops, 153
- loops, 145
- iOS, 5
- iPadOS, 5
is not
operator, 122, 123
is
operator, 122, 123
isabls()
method, 95
isalnum()
method, 140, 188, 190
isalpha()
method, 140, 188
isascii()
method, 140, 188
isdecimal()
method, 188
isdigit()
method, 188
isfile()
method, 82–83
isidentifier()
method, 188
isinstance()
function, 169
islower()
method, 188, 190
isnumeric()
method, 140, 188, 190
isprintable()
method, 188
isspace()
method, 140, 188
issubclass()
function, 169
istitle()
method, 188
isupper()
method, 188, 190, 200–203
items()
method, 251, 258–259
iter()
function, 169
J
join()
method, 189
- joining strings using concatenation operator, 196
K
KeyboardInterrupt
, 222
KeyError
, 222
keys()
method, 258–259
- key/value pairs
- adding to dictionaries, 254–255
- removing from dictionaries, 256–257
- returning from dictionaries, 258–259
L
LANG
variable, 93
- launching
- scripts via command line, 31
- Visual Studio Code, 22–23
- leading spaces, 192
len()
function, 169, 191
- less than (<) operator, 118
- less than or equal to (<=) operator, 118
- Linux
- about, 5
- installing
- Python, 14–15
- Visual Studio Code on, 21
- updating Python, 15
- versions for, 7
list
data type, 55
list()
function, 75, 169, 170
listdir()
method, 80
- lists
- about, 236–237
- accessing data in, 244–245
- adding items to, 240–241
- compared to arrays, 237
- compared to sets, 237
- compared to tuples, 237
- creating, 238
- creating
for
loops that use, 148
- of files and directories, 80–81
- locating items in, 244–245
- methods for, 239
- of methods/variables in modules/objects, 47
- removing items from, 242–243
- sorting items in, 246–247
- using
for
loops with, 146–147
- working with, 70–71
ljust()
method, 189
- loading
os
(Operating System) module, 80–81
locals()
function, 169
- logical errors, 221
- logical operators, 120–121
LOGNAME
variable, 93
- loops
for
, 146–149
- about, 144–145
break
statements in, 154–155
continue
statements in, 156–157
else
statements in, 158–159
- infinite, 151
- nesting, 160–161
while
, 150–153
lower()
method, 188, 203
- low-level programming language, 54
lstrip()
method, 189
M
- macOS
- about, 5
- installing Visual Studio Code on, 21
- versions for, 7
- Macs
- installing Python, 12–13
- updating versions on, 13
main()
function, 30–31
makedirs()
method, 84–87
make_title()
function, 201–202
maketrans()
method, 189
map()
function, 169
- mapping data type, 56
- mathematicians, as Python users, 5
max()
function, 169
- members, 66
- membership operators, 124–125
MemoryError
, 222
memoryview()
function, 169
- methods
- about, 270
append()
, 239, 240–241
basename()
, 95
capitalize()
, 188
casefold()
, 188, 203
center()
, 188, 189
chdir()
, 82–83, 92
- for checking/changing case, 188
clear()
, 239, 242–243, 251, 256
close()
, 97, 100–101
cm2cf()
, 276
copy()
, 90, 239, 251, 253
copytree()
, 90
count()
, 188, 190, 239, 244–245
- for dictionaries, 251
- dictionary, 251
dirname()
, 95
encode()
, 188, 189
endswith()
, 188, 190
expandtabs()
, 189
expanduser()
, 82–83, 92
extend()
, 239, 240–241
find()
, 188, 189, 198–199
- for finding within strings, 189
format()
, 168, 188, 189
.format
, 206–207, 212–213
format_map()
, 189
fromkeys()
, 251, 252–253
get()
, 251
getcwd()
, 80
getInfo()
, 274, 277
getuser()
, 92
glob()
, 80
index()
, 189, 198–199, 239, 244–245
insert()
, 239
isabls()
, 95
isalnum()
, 140, 188, 190
isalpha()
, 140, 188
isascii()
, 140, 188
isdecimal()
, 188
isdigit()
, 188
isfile()
, 82–83
isidentifier()
, 188
islower()
, 188, 190
isnumeric()
, 140, 188, 190
isprintable()
, 188
isspace()
, 140, 188
istitle()
, 188
isupper()
, 188, 190, 200–203
items()
, 251, 258–259
join()
, 189
keys()
, 258–259
- for laying out strings, 189
listdir()
, 80
- listing in modules/objects, 47
- for lists, 239
ljust()
, 189
lower()
, 188, 203
lstrip()
, 189
makedirs()
, 84–87
maketrans()
, 189
- of modules, 48–49
move()
, 90, 91
partition()
, 189, 192
pop()
, 239, 242–243, 251, 256
popitem()
, 251, 256
read()
, 104–105
readable()
, 105
reload()
, 47
remove()
, 88, 239, 242–243
rename()
, 88
replace()
, 188, 189
- for returning information about strings, 188
reverse()
, 239, 246–247
rfind()
, 189, 198–199
rindex()
, 189
rjust()
, 189
rmdir()
, 86–87, 88
rmtree()
, 86
rpartition()
, 189
rsplit()
, 189
rstrip()
, 189
seek()
, 104–105
seekable()
, 105
setdefault()
, 251, 254–255
showClassInfo()
, 275
shutil.copy()
, 89
shutil.copyfile()
, 89
sort()
, 239, 246–247
split()
, 94–95, 189
splitext()
, 94–95
splitlines()
, 189
startswith()
, 188
- string, 188–189
strip()
, 189
swapcase()
, 188
title()
, 188, 200–203
today()
, 167
- for transforming strings, 189
translate()
, 189
update()
, 251, 254–255
upper()
, 188
values()
, 251, 258–259
writable()
, 105
write()
, 102–103, 104–105
zfill()
, 188, 189, 193
min()
function, 169
mkdir()
function, 84–87
- modifying
- order of operations, 113
- order of precedence using parentheses, 115
- string capitalization, 200–203
ModuleNotFoundError
, 222
- modules
- importing
- about, 44–48
- under an alias, 46
- objects from, 45
- scripts into, 31
- listing methods/variables in, 47
- methods of, 48–49
- reloading, 47
- unimporting, 49
- for working with files and directories, 79
- modulus, 112
move()
method, 90, 91
- moving files and directories, 88–91
- multiline strings
- creating, 186–187
- creating informal comments using, 40
- mutable dictionary, 248
- mutable lists, 236
N
NameError
, 222
- navigating directories, 82–83
- nested
if
statements, 140–141
- nested
try…except
blocks, creating, 230–231
- nesting loops, 145, 160–161
- new-line characters, creating multiline strings using, 187
next()
function, 169
- not equal to (!=) operator, 118
not in
operator, 124
NOT
(~) operator, 120, 126
NotImplementedError
, 222
- numeric conditions,
while
loop using, 150
- numeric data types, 54–55
O
object()
function, 169
- objects
- importing
- about, 44–48
- under an alias, 46
- from modules, 45
- listing methods/variables in, 47
- unimporting, 49
oct()
function, 75, 169, 170, 171
- octal strings
- converting to decimal values, 171
- returning, 171
OLDPWD
variable, 93
open()
function, 79, 96–109, 169, 170
- opening
- files, 98–99
- files for reading and writing, 104–105
- operating system
- determining, 92
- verifying, 81
- operations, order of, 113
- operators
- arithmetic, 112–115
- assignment, 116–117
- bitwise, 126–127
- comparison, 118–119
- identity, 122–123
- logical, 120–121
- membership, 124–125
OR
(|) operator, 120, 126
ord()
function, 75, 170
- order of operations, 113
- ordered data, 55
- ordered dictionary, 248, 249
- ordered lists, 236
os
(Operating System) module, 79, 80–81, 88, 90, 93
OSError
, 222
OverflowError
, 222
P
- parameters
- about, 164
- creating functions
- with no returns and no, 176
- with no returns but, 173
- with optional, 178–179
- with returns and, 172
- with returns but no, 174–175
- parent directory, 78
- parentheses, changing order of precedence using, 115
- Parentheses, Exponentiation, Multiplication, Division, Addition, and Subtraction (PEMDAS), 112, 113
partition()
method, 189, 192
- PATH variable, 11
- PEMDAS (Parentheses, Exponentiation, Multiplication, Division, Addition, and Subtraction), 112, 113
- + operator, 116
- + = operator, 116
pop()
method, 239, 242–243, 251, 256
popitem()
method, 251, 256
pow()
function, 170
print()
function, 53, 58–59, 150, 154, 164, 167, 170, 171, 277
- programming language, 4
property()
function, 170
PWD
variable, 93
- PyCharm, 18
- Python
- about, 4–5
- applying themes, 22–23
- choosing versions, 6–7
- configuring Visual Studio Code, 26–27
- development tools for, 16–19
- downloading
- Visual Studio Code, 20–21
- on Windows, 8–11
- installing
- on Linux, 14–15
- on Macs, 12–13
- Visual Studio Code, 20–21
- Visual Studio Code extensions, 24–25
- on Windows, 8–11
- launching Visual Studio Code, 22–23
- upgrading on Windows, 11
- Python Software Foundation (website), 5
Q
- quotes
- about, 69
- creating multiline strings using triple, 186
- inside strings, 185
R
r
mode, 96
r +
mode, 96
range
data type, 55
range()
function, 147, 170
- Read and Write Mode, 96, 108
read()
method, 104–105
- Read Mode, 96, 108
readable()
method, 105
- reading
- opening files for writing and, 104–105
- text files, 108–109
ReferenceError
, 222
- release candidates, 7
reload()
method, 47
- reloading modules, 47
remove()
method, 88, 239, 242–243
- removing
- items
- from lists, 242–243
- from tuples, 65
- key/value pairs from dictionaries, 256–257
rename()
method, 88
- renaming files and directories, 88–91
- repeating strings, 196–197
- repetition, nesting loops to create complex, 145
- repetition operator, 197
- repetitive code, 37
replace()
method, 188, 189
repr()
function, 170
return
statement, 164, 165
- returning
- binary strings, 171
- class attributes, 269
- hexadecimal strings, 171
- home directory, 92
- information about strings, 190–191
- information using environment variables, 93
- keys from dictionaries, 258–259
- octal strings, 171
- parts of strings via slicing, 194–195
- username, 92
- values, 250
- values from dictionaries, 258–259
- returns
- about, 164
- creating functions
- with no parameters and no, 176
- with no parameters but, 174–175
- with parameters and, 172
- with parameters but no, 173
reverse()
method, 239, 246–247
reversed()
function, 170
rfind()
method, 189, 198–199
rindex()
method, 189
rjust()
method, 189
rmdir()
method, 86–87, 88
rmtree()
method, 86
round()
function, 170
rpartition()
method, 189
rsplit()
method, 189
rstrip()
method, 189
- running
- code in Visual Studio Code, 34–37
- scripts
- about, 58–59
- in Terminal window, 39
- runtime errors, 220
RuntimeError
, 222
S
- saving scripts in Visual Studio Code, 32–33
- scientists, as Python users, 5
- scripts
- creating, 58–59
- creating in Visual Studio Code, 32–33
- importing
- about, 31
- scripts into other, 31
- launching via command line, 31
- running
- about, 58–59
- in Terminal window, 39
- saving in Visual Studio Code, 32–33
seek()
method, 104–105
seekable()
method, 105
self
keyword, 266–267
- semantic errors, 221
- sequence data type, 55
set
data type, 56
set()
function, 67, 75, 170
setattr()
function, 168, 170
setdefault()
method, 251, 254–255
- sets
- compared to lists, 236, 237
- working with, 66–67
- setting
- class attributes, 268–269
- instance attributes, 268–269
SHELL
variable, 93
showClassInfo()
method, 275
shutil
(Shell Utility) module, 79, 87, 88, 90, 91
shutil.copy()
method, 89
shutil.copyfile()
method, 89
- signed right shift (>>), 126
- single quotes, 69
- # (single-line) character, 40, 43
- single-line strings, creating, 184–185
slice()
function, 170
- slicing, returning parts of strings via, 194–195
sort()
method, 239, 246–247
sorted()
function, 170, 171
- sorting items in lists, 246–247
split()
method, 94–95, 189
splitext()
method, 94–95
splitlines()
method, 189
- splitting file paths, 94–95
- stable build, 7
startswith()
method, 188
- statements
- about, 164
break
, 145,149, 151, 154, 155
continue
, 145,156–157
else
, 158–159
from…import
, 44
if…elif
, 130, 136–137
if…elif…else
, 130, 138–139
if…else
, 130, 134–135
import
, 44, 79
return
, 164, 165
- static methods
- static typing, 52
staticmethod()
function, 170, 276
StopIteration
, 223
- storing
- floating-point numbers, 54
- integers, 54
str
data type, 55
str()
function, 68–69, 75, 170
- strings
- about, 182–183
- backslash inside, 185
- building
- about, 182
for
loops that iterate through, 148–149
- using
.format
method, 212–213
- using f-strings, 214–215
- using interpolation operator, 210–211
- using template strings, 216–217
- checking/changing capitalization of, 200–203
- cleaning up, 192–193
- concatenating, 196–197
- formatting
- about, 204–205
- using
.format
method, 206–207
- using f-strings, 207–209
- using template strings, 209
- multiline, 186–187
- quotes inside, 185
- repeating, 196–197
- returning
- information about, 190–191
- parts of, via slicing, 194–195
- searching for strings inside other, 198–199
- single-line, 184–185
- strings, 204–209
- tools for manipulating, 183
- transforming, 192–193
- working with, 68–69
strip()
method, 189
- Sublime Text, 19
sum()
function, 170
- sunsetting, 6
super()
function, 170
- SUSE, 15
swapcase()
method, 188
- syntax errors, 220–221
SyntaxError
, 223
sys
module, 92
SystemError
, 223
SystemExit
, 223
- systems, getting information about, 92–93
T
TabError
, 223
- template strings
- about, 204
- building strings using, 216–217
- formatting strings using, 209
- Terminal app, 12–13
- Terminal window
- Ctrl + C in, 153
- executing commands in, 38
- running scripts in, 39
- text
- building strings
- with
.format
method, 212–213
- with f-strings, 214–215
- with interpolation operator, 210–211
- with template strings, 216–217
- changing string capitalization, 200–203
- checking string capitalization, 200–203
- cleaning up strings, 192–193
- concatenating strings, 196–197
- creating
- multiline strings, 186–187
- single-line strings, 184–185
- repeating strings, 196–197
- returning
- information about strings, 190–191
- part of strings via slicing, 194–195
- searching for strings inside other strings, 198–199
- string methods, 188–189
- strings, 182–183
- tools for building strings, 204–209
- transforming strings, 192–193
- text files, reading, 108–109
- themes, applying, 22–23
- Thonny, 18
title()
method, 188, 200–203
today()
method, 167
- tools
- for building strings, 204–209
- for manipulating strings, 183
- trailing spaces, 192
- transforming strings, 192–193
translate()
method, 189
- trapping exceptions, 225, 226–227
- troubleshooting floating-point numbers, 115
try…except
block, 224–225, 230–231
tuple
data type, 55
tuple()
function, 75, 170
- tuples
- compared to lists, 236, 237
- empty, 65
- working with, 64–65
type
command, 53, 264–265
type()
function, 170
TypeError
, 223
U
UnboundLocalError
, 223
- Unicode Transformation Formats (UTF), 183
UnicodeDecodeError
, 223
UnicodeEncodeError
, 223
UnicodeError
, 223
UnicodeTranslateError
, 223
- unimporting modules/objects, 49
update()
method, 251, 254–255
- updating
- Python on Linux, 15
- versions on Macs, 13
- Visual Studio Code, 27
- upgrading Python on Windows, 11
upper()
method, 188
USER
variable, 93
- username, returning, 92
- users, getting information about, 92–93
V
ValueError
, 223
- values
- assigning to variables, 53
- returning, 250
values()
method, 251, 258–259
- van Rossum, Guido, 7
- variables
- about, 52–53
- assigning values to, 53
- Boolean values, 62–63
- converting data types, 74–75
- creating, 53
- data types, 54–57, 74–75
- dictionaries, 72–73
- floating-point values, 60–61
- formatting strings with, 208
- integers, 58–59
- listing in modules/objects, 47
- lists, 70–71
- sets, 66–67
- strings, 68–69
- tuples, 64–65
- verifying
- file status, 100–101
- operating system, 81
- string capitalization, 200–203
- versions, 81
- versions
- choosing, 6–7
- updating on Macs, 13
- verifying, 81
- Visual Studio Code
- about, 19
- Auto Save feature, 33
- auto saving in, 27
- configuring, 26–27
- creating scripts in, 32–33
- downloading, 20–21
- installing
- about, 20–21
- extensions for, 24–25
- on Linux, 21
- on macOS, 21
- launching, 22–23
- running code in, 34–37
- saving scripts in, 32–33
- updating, 27
- writing code in, 34–37
W
w
mode, 96
w +
mode, 96
- web developers, as Python users, 5
- websites
- Atom, 19
- IDLE app, 18
- PyCharm, 18
- Python Software Foundation, 5
- Sublime Text, 19
- Thonny, 18
- Visual Studio Code, 20
while
loops
- how they work, 150–151
- using for indefinite iteration, 144–145
- Windows
- about, 5
- downloading Python, 8–11
- installing Python, 8–11
- upgrading Python, 11
- versions for, 7
- Windows path, 11
- Wolfram Mathematics, 4
writable()
method, 105
- Write and Read Mode, 96
write()
method, 102–103, 104–105
- Write Mode, 96
- writing
- code in Visual Studio Code, 34–37
- data to files, 102–103
- opening files for reading and, 104–105
X
x
mode, 96
XOR
(^) operator, 126
Z
- zero-based numbering, 71
ZeroDivisionError
, 223
- zero-fill left shift (<<), 126
zfill()
method, 188, 189, 193
zip()
function, 170
..................Content has been hidden....................
You can't read the all page of ebook, please click
here login for view all page.