PYTHON PROGRAMMIN A to Z: A Comprehensive Guide to Programming Excellence
Python A to Z is your trusted companion in the realm of one of the world's most versatile programming languages. Em
123
90
18MB
English
Pages 399
Year 2024
Report DMCA / Copyright
DOWNLOAD EPUB FILE
Table of contents :
Why Should You Learn to Write Programs? 9
1.1Creativity and motivation 14
1.2Computer hardware architecture 16
1.3Understanding programming 21
1.4Words and sentences 23
1.5Conversing with Python 30
1.6Terminology: Interpreter and compiler 33
1.7Writing a program 40
1.8What is a program? 42
1.9The building blocks of programs 46
1.10What could possibly go wrong? 49
1.11Debugging 77
1.12The learning journey 81
1.13Glossary 84
1.14Exercises 88
Variables, Expressions, and Statements 91
2.1Values and types 91
2.2Variables 95
2.3Variable names and keywords 97
2.4Statements 99
2.5Operators and operands 101
2.6Expressions 103
2.7Order of operations 105
2.8Modulus operator 107
2.9String operations 108
2.10Asking the user for input 109
2.11Comments 113
2.12Choosing mnemonic variable names 115
2.13Debugging 120
2.14Glossary 153
2.15Exercises 155
Conditional Execution 129
3.1Boolean expressions 129
3.2Logical operators 131
3.3Conditional execution 132
3.4Alternative execution 136
3.5Chained conditionals 138
3.6Nested conditionals 140
3.7Catching exceptions using try and except 143
3.8Short-circuit evaluation of logical expressions 147
3.9Debugging 152
3.10Glossary 153
3.11Exercises 156
Functions 159
4.1Function calls 159
4.2Built-in functions 161
4.3Type conversion functions 163
4.4Math functions 165
4.5Random numbers 169
4.6Adding new functions 173
4.7Definitions and uses 177
4.8Flow of execution 180
4.9Parameters and arguments 182
4.10Fruitful functions and void functions 185
4.11Why functions? 189
4.12Debugging 191
4.13Glossary 193
4.14Exercises 196
Iteration 201
5.1Updating variables 201
5.2The while statement 203
5.3Infinite loops 206
5.4Finishing iterations with continue 210
5.5Definite loops using for 212
5.6Loop patterns 215
5.6.1Counting and summing loops 215
5.6.2Maximum and minimum loops 219
5.7Debugging 223
5.8Glossary 225
5.9Exercises 226
Strings 228
6.1A string is a sequence 228
6.2Getting the length of a string using Len 230
6.3Traversal through a string with a loop 231
6.4String slices 234
6.5Strings are immutable 236
6.6Looping and counting 237
6.7The in operator 239
6.8String comparison 240
6.9String methods 241
6.10Parsing strings 248
6.11Formatted String Literals 250
6.12Debugging 251
6.13Glossary 256
6.14Exercises 258
Files 259
7.1Persistence 259
7.2Opening files 261
7.3Text files and lines 264
7.4Reading files 267
7.5Searching through a file 272
7.6Letting the user choose the file name 279
7.7Using try, except, and open 282
7.8Writing files 286
7.9Debugging 289
7.10Glossary 291
7.11Exercises 292
Lists 295
8.1A list is a sequence 295
8.2Lists are mutable 297
8.3Traversing a list 299
8.4List operations 301
8.5List slices 302
8.6List methods 304
8.7Deleting elements 306
8.8Lists and functions 308
8.9Lists and strings 312
8.10Parsing lines 315
8.11Objects and values 317
8.12Aliasing 320
8.13List arguments 322
8.14Debugging 325
8.15Glossary 337
8.16Exercises 338
Dictionaries 348
9.1Dictionary as a set of counters 348
9.2Dictionaries and files 353
9.3Looping and dictionaries 357
9.4Advanced text parsing 360
9.5Debugging 364
9.6Glossary 367
9.7Exercises 368
Tuples 371
10.1Tuples are immutable 371
10.2Comparing tuples 375
10.3Tuple assignment 378
10.4Dictionaries and tuples 383
10.5Multiple assignments with dictionaries 384
10.6The most common words 387
10.7Using tuples as keys in dictionaries 390
10.8Sequences: strings, lists, and tuples - Oh My! 391
10.9List comprehension 394
10.10 Debugging 395
10.11Glossary 396
10.12Exercises 398