Python is one of the most widely used programming languages in education, research, and industry. Its readable syntax and broad standard library make it a common choice for introductory programming courses as well as practical scripting and application development.
Learning Python provides a foundation for understanding core programming concepts such as variables, control flow, data structures, functions, and object-oriented programming. It also opens pathways into areas like automation, data analysis, graphical interfaces, and software development.
About the book
A Practical Introduction to Python Programming by Brian Heinold was originally developed as course notes for an introductory programming class at Mount St. Mary’s University. The book is designed for readers with little or no prior programming experience, while also remaining useful for those who already know how to program and want to learn Python.
The text combines tutorial-style explanations with reference-style summaries. It emphasizes short example programs, practical exercises, and concise demonstrations of key features. The author intentionally avoids excessive technical detail in early chapters, introducing complexity progressively.
The book is not intended as a comprehensive preparation for a career in software engineering. Instead, it focuses on practical programming skills, mathematical-style problem solving, small utilities, and simple games.
What you will learn
Readers working through the book will develop practical knowledge of:
- Core Python syntax and program structure
- Variables, input/output, and expressions
- Control flow using
if,for, andwhilestatements - Strings, lists, dictionaries, and other built-in data structures
- File handling and text processing
- Functions and argument handling
- Object-oriented programming concepts including classes and inheritance
- Exception handling
- Regular expressions
- Use of standard modules such as
math,itertools, andcollections - GUI programming with Tkinter
- Intermediate topics such as recursion, higher-order functions, and modules
The book progresses from foundational programming constructs (Part I), to graphical user interface programming (Part II), and then to more advanced and intermediate Python topics (Part III).
Exercises are included throughout, reinforcing practical understanding and encouraging hands-on practice.
Table of contents
- Part I – Basics
- 1 Getting Started
1.1 Installing Python
1.2 IDLE
1.3 A first program
1.4 Typing things in
1.5 Getting input
1.6 Printing
1.7 Variables
1.8 Exercises - 2 For loops
2.1 Examples
2.2 The loop variable
2.3 The range function
2.4 A Trickier Example
2.5 Exercises - 3 Numbers
3.1 Integers and Decimal Numbers
3.2 Math Operators
3.3 Order of operations
3.4 Random numbers
3.5 Math functions
3.6 Getting help from Python
3.7 Using the Shell as a Calculator
3.8 Exercises - 4 If statements
4.1 A Simple Example
4.2 Conditional operators
4.3 Common Mistakes
4.4 elif
4.5 Exercises - 5 Miscellaneous Topics I
5.1 Counting
5.2 Summing
5.3 Swapping
5.4 Flag variables
5.5 Maxes and mins
5.6 Comments
5.7 Simple debugging
5.8 Example programs
5.9 Exercises - 6 Strings
6.1 Basics
6.2 Concatenation and repetition
6.3 The in operator
6.4 Indexing
6.5 Slices
6.6 Changing individual characters of a string
6.7 Looping
6.8 String methods
6.9 Escape characters
6.10 Examples
6.11 Exercises - 7 Lists
7.1 Basics
7.2 Similarities to strings
7.3 Built-in functions
7.4 List methods
7.5 Miscellaneous
7.6 Examples
7.7 Exercises - 8 More with Lists
8.1 Lists and the random module
8.2 split
8.3 join
8.4 List comprehensions
8.5 Using list comprehensions
8.6 Two-dimensional lists
8.7 Exercises - 9 While loops
9.1 Examples
9.2 Infinite loops
9.3 The break statement
9.4 The else statement
9.5 The guessing game, more nicely done
9.6 Exercises - 10 Miscellaneous Topics II
10.1 str, int, float, and list
10.2 Booleans
10.3 Shortcuts
10.4 Short-circuiting
10.5 Continuation
10.6 pass
10.7 String formatting
10.8 Nested loops
10.9 Exercises - 11 Dictionaries
11.1 Basics
11.2 Dictionary examples
11.3 Working with dictionaries
11.4 Counting words
11.5 Exercises - 12 Text Files
12.1 Reading from files
12.2 Writing to files
12.3 Examples
12.4 Wordplay
12.5 Exercises - 13 Functions
13.1 Basics
13.2 Arguments
13.3 Returning values
13.4 Default arguments and keyword arguments
13.5 Local variables
13.6 Exercises - 14 Object-Oriented Programming
14.1 Python is object-oriented
14.2 Creating your own classes
14.3 Inheritance
14.4 A playing-card example
14.5 A Tic-tac-toe example
14.6 Further topics
14.7 Exercises - Part II – Graphics
- 15 GUI Programming with Tkinter
15.1 Basics
15.2 Labels
15.3 grid
15.4 Entry boxes
15.5 Buttons
15.6 Global variables
15.7 Tic-tac-toe - 16 GUI Programming II
16.1 Frames
16.2 Colors
16.3 Images
16.4 Canvases
16.5 Checkbuttons and Radiobuttons
16.6 Text widget
16.7 Scale widget
16.8 GUI Events
16.9 Event examples - 17 GUI Programming III
17.1 Titlebar
17.2 Disabling things
17.3 Getting the state of a widget
17.4 Messageboxes
17.5 Destroying things
17.6 Updating
17.7 Dialogs
17.8 Menubars
17.9 New windows
17.10 pack
17.11 StringVar
17.12 More with GUIs - 18 Further Graphical Programming
18.1 Python 2 vs Python 3
18.2 The Python Imaging Library
18.3 Pygame - Part III – Intermediate Topics
- 19 Miscellaneous topics III
19.1 Mutability and References
19.2 Tuples
19.3 Sets
19.4 Unicode
19.5 sorted
19.6 if-else operator
19.7 continue
19.8 eval and exec
19.9 enumerate and zip
19.10 copy
19.11 More with strings
19.12 Miscellaneous tips and tricks
19.13 Running your Python programs on other computers - 20 Useful modules
20.1 Importing modules
20.2 Dates and times
20.3 Working with files and directories
20.4 Running and quitting programs
20.5 Zip files
20.6 Getting files from the internet
20.7 Sound
20.8 Your own modules - 21 Regular expressions
21.1 Introduction
21.2 Syntax
21.3 Summary
21.4 Groups
21.5 Other functions
21.6 Examples - 22 Math
22.1 The math module
22.2 Scientific notation
22.3 Comparing floating point numbers
22.4 Fractions
22.5 The decimal module
22.6 Complex numbers
22.7 More with lists and arrays
22.8 Random numbers
22.9 Miscellaneous topics
22.10 Using the Python shell as a calculator - 23 Working with functions
23.1 First-class functions
23.2 Anonymous functions
23.3 Recursion
23.4 map, filter, reduce, and list comprehensions
23.5 The operator module
23.6 More about function arguments - 24 The itertools and collections modules
24.1 Permutations and combinations
24.2 Cartesian product
24.3 Grouping things
24.4 Miscellaneous things from itertools
24.5 Counting things
24.6 defaultdict - 25 Exceptions
25.1 Basics
25.2 Try/except/else
25.3 try/finally and with/as
25.4 More with exceptions - Bibliography
Index
Book details
- Title: A Practical Introduction to Python Programming
- Author(s): Brian Heinold
- Main category: Programming
- Subcategory: Python
- Language: English
- License: Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported
More books in: Programming, Python
Legal notice: This book is shared for educational purposes only. The content is distributed under Creative Commons licenses or with explicit permission from the author. FreeProgrammingBooks may host files that comply with their respective licenses.