Contents
1 The First Few Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1.1 What Is a Program? And What Is Programming? . . . . . . . . . . . . . . . .
1
1.1.1 Installing Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
1.2 A Python Program with Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
1.2.1 The Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
1.2.2 Dissecting the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
1.2.3 Why Use Variables? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
1.2.4 Mathematical Notation Versus Coding . . . . . . . . . . . . . . . . . 10
1.2.5 Write and Run Your First Program . . . . . . . . . . . . . . . . . . . . 10
1.3 A Python Program with a Library Function . . . . . . . . . . . . . . . . . . . . . 12
1.4 Importing from Modules and Packages . . . . . . . . . . . . . . . . . . . . . . . . 14
1.4.1 Importing for Use Without Prefix . . . . . . . . . . . . . . . . . . . . . . 14
1.4.2 Importing for Use with Prefix . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.4.3 Imports with Name Change . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4.4 Importing from Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4.5 The Modules/Packages Used in This Book . . . . . . . . . . . . . . 19
1.5 A Python Program with Vectorization and Plotting . . . . . . . . . . . . . . 19
1.6 Plotting, Printing and Input Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.6.1 Plotting with Matplotlib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.6.2 Printing: The String Format Method . . . . . . . . . . . . . . . . . . . 27
1.6.3 Printing: The f-String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1.6.4 User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.7 Error Messages and Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.8 Concluding Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.8.1 Programming Demands You to Be Accurate! . . . . . . . . . . . . 34
1.8.2 Write Readable Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.8.3 Fast Code or Slower and Readable Code? . . . . . . . . . . . . . . 35
1.8.4 Deleting Data No Longer in Use . . . . . . . . . . . . . . . . . . . . . . 36
1.8.5 Code Lines That Are Too Long . . . . . . . . . . . . . . . . . . . . . . . 36
1.8.6 Where to Find More Information? . . . . . . . . . . . . . . . . . . . . . 36
1.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
xv
Précédent

- 14/350

Suivant