Python Programming Course Overview
Python Programming Course Overview
[Link]
1 Introduction 11
1.1 A few words about the origin of this course... 11
1.2 Acknowledgments 11
1.3 Before starting . . . . . . . . . . . . . . 12 . . . . . . . . . . . . . . . .
1.4 What is Python? 12
1.5 First contact with Python under Linux........................................................ 13
1.6 Premier Python program. 14
1.6.1 Call of the interpreter. 14
1.6.2 Direct call of the script ...14
1.7 Commentaires . . . . . . . . . . . . . . . .15. . . . . . . . . . . . . . .
1.8 Concept of instruction block and indentation 15
1.9 Python 2 or Python 3? 16
2Variables 17
2.1 Definition of a variable. 17
2.2 Types of variables 18
2.3 Naming of Variables 18
2.4 Operations 18
2.4.1 Operations on numeric types 18
2.4.2 Operations on character strings 19
2.4.3 Illicit operations. 19
2.5 The type() function . . . . . . . . . . . . . . . 20. . . . . . . . . . . . .
2.6 Type conversion 20
2.7 Note on the division. 20
2.8 Note on vocabulary and syntax 21
3 Display 23
3.1 Formatted writing. 23
3.2 Old method of string formatting 26
3.3 Note on vocabulary and syntax 27
3.4 Exercises. 27
3.4.1 Display in the interpreter and in a program... 27
3.4.2 Poly-A 27
3.4.3 Poly-A and poly-GC 27
3.4.4 Formatted writing. 27
3.4.5 Formatted writing 28
4 Lists 29
4.1 Definition 29
4.2 Utilization 29
4.3 Operation on lists... 30
4.4 Negative indexing. 31
3
Table of contents Table of contents
4.5 Tranches 31
4.6 Function len(). 32
4.7 The functions range() and list() . . . . . . . . . . . . 32
. . . . . . . . . . . .
4.8 Lists of lists 33
4.9 Exercises... 33
4.9.1 Days of the week 34
4.9.2 Seasons 34
4.9.3 Table of 9 34
4.9.4 Even numbers. 34
6Tests 47
6.1 Definition ...47
6.2 Tests with multiple cases 47
6.3 Multiple tests. 49
6.4 Instructions break and continue. 50
6.5 Value tests on real numbers . . . . . . . . . . . . 50 . . . . . . . . . . . . .
6.6 Exercises... 51
6.6.1 Days of the week 51
6.6.2 Complementary sequence of a DNA strand 51
6.6.3 Minimum of a list . . . . . . . . . . . . . . . . . . . 51. . . .
6.6.4 Frequency of amino acids. 51
6.6.5 Notes and mention of a student 52
6.6.6 Even numbers. 52
6.6.7 The riddle of Father Fouras. 52
6.6.8 Syracuse Conjecture (exercise +++). 52
6.6.9 Simple attribution of the secondary structure of the residues of a protein (exercise
+++). . . . . . . . . . . . . . . . . . . . .53. . . . . . . . . . . . . . . . .
6.6.10 Determination of prime numbers less than 100 (exercise +++). 53
6.6.11 Searching for a number by dichotomy (exercise +++) 54
7 Files 57
7.1 Reading from a file... 57
7.1.1 Method read(). . . . . . . . . . . . . 58 . . . . . . . . . . . . . .
7.1.2 Readline() method... 58
7.1.3 seek() and tell() methods. . . . . . . . . . . .59 . . . . . . . . . .
7.1.4 Iterations directly on the file... 59
7.2 Writing to a file ... 60
7.3 Optimized method for opening and closing files. 60
7.4 Note on carriage returns under Unix and under Windows 61
7.5 Importance of type conversions with files... 62
7.6 Exercises................................................... 62
7.6.1 Reading and line jump 62
7.6.2 Writing and line break 62
7.6.3 Secondary structures. 62
7.6.4 Spiral (exercise +++) 62
8 Modules 65
8.1 Definition 65
8.2 Importation of modules 65
8.3 Getting help on imported modules. 66
8.4 Current Modules. 67
8.5 Module sys: passing arguments. 68
8.6 Module os 69
8.7 Exercises. 70
8.7.1 Square root. 70
8.7.2 Cosine 70
8.7.3 List of files in a directory 70
8.7.4 Timed display. 70
8.7.5 Random sequences of digits 70
8.7.6 Random base sequences... 71
8.7.7 Date of birth. 71
8.7.8 Determination of the number pi by the Monte Carlo method (exercise 71+++). . .
9Functions 73
9.1 Principles and generalities 73
9.2 Definition 74
9.3 Passing of arguments... 75
9.4 Local variables and global variables... 76
9.5 Exercises... 80
9.5.1 Functions and pythontutor 80
9.5.2 Power function. 81
9.5.3 Pyramid function. 81
9.5.4 Prime number function. 81
9.5.5 Complementary function... 81
9.5.6 Distance function. 82
9.5.7 Distribution functions and statistics 82
9.5.8 Distance to origin function. 82
9.5.9 Area under the curve function (exercise +++) 82
10 Plus on strings 85
10.1 Preamble 85
10.2 Strings and Lists. 85
10.3 Special characters. 86