freeprogrammingbooks.com

Introduction to Python Programming

By Udayan Das; Aubrey Lawson; Chris Mayfield; Narges Norouzi (Senior Contributing Authors)

Introduction to Python Programming is an openly licensed textbook developed by OpenStax, an initiative of Rice University.

Python is one of the most widely used programming languages in education and industry. It is commonly adopted in introductory computer science courses because of its clear syntax and broad applicability across disciplines such as business, science, statistics, and data science.

A structured introduction to Python provides learners with fundamental programming concepts, problem-solving skills, and exposure to practical tools that support interactive learning. For students and professionals entering technical fields, a solid foundation in Python is often a prerequisite for further study in software development, data analysis, and related areas.

About the book

Introduction to Python Programming is an openly licensed textbook developed by OpenStax, an initiative of Rice University. The book provides a comprehensive foundation in programming concepts and skills aligned with most introductory college-level courses.

The text is designed for a diverse learner audience, including students pursuing computer science, business, science, social science, statistics, data science, and related fields. It emphasizes hands-on learning through an integrated Python Code Runner that allows readers to write and execute code directly in the browser.

Each chapter is organized into sections that include learning objectives, concept explanations, interactive learning questions, and programming practice exercises. The material combines concise textual explanations with video-based animations that demonstrate step-by-step code execution and reinforce core programming ideas.

No prior advanced programming experience is indicated; the structure and pedagogical approach suggest it is intended for beginners or those in an introductory programming course.

What you will learn

Readers working through this book will develop foundational programming skills using Python. The content progresses from basic syntax and data types to more advanced topics such as object-oriented programming and introductory data science tools.

Key areas of learning include:

  • Writing and understanding Python statements and expressions
  • Working with variables, strings, numbers, and type conversion
  • Applying control flow structures such as conditionals and loops
  • Defining and using functions and modules
  • Manipulating core data structures including lists, tuples, and dictionaries
  • Implementing object-oriented concepts such as classes, inheritance, and operator overloading
  • Using recursion to solve computational problems
  • Reading from and writing to files, including CSV files
  • Handling and raising exceptions
  • Exploring introductory data science tools such as NumPy and Pandas
  • Performing exploratory data analysis and data visualization

The integrated programming environment supports immediate practice, while embedded learning questions address common misconceptions and reinforce conceptual understanding.

Table of contents

  • Preface
  • 1 Statements
    • Introduction
    • 1.1 Background
    • 1.2 Input/output
    • 1.3 Variables
    • 1.4 String basics
    • 1.5 Number basics
    • 1.6 Error messages
    • 1.7 Comments
    • 1.8 Why Python?
    • 1.9 Chapter summary
  • 2 Expressions
    • Introduction
    • 2.1 The Python shell
    • 2.2 Type conversion
    • 2.3 Mixed data types
    • 2.4 Floating-point errors
    • 2.5 Dividing integers
    • 2.6 The math module
    • 2.7 Formatting code
    • 2.8 Python careers
    • 2.9 Chapter summary
  • 3 Objects
    • Introduction
    • 3.1 Strings revisited
    • 3.2 Formatted strings
    • 3.3 Variables revisited
    • 3.4 List basics
    • 3.5 Tuple basics
    • 3.6 Chapter summary
  • 4 Decisions
    • Introduction
    • 4.1 Boolean values
    • 4.2 If-else statements
    • 4.3 Boolean operations
    • 4.4 Operator precedence
    • 4.5 Chained decisions
    • 4.6 Nested decisions
    • 4.7 Conditional expressions
    • 4.8 Chapter summary
  • 5 Loops
    • Introduction
    • 5.1 While loop
    • 5.2 For loop
    • 5.3 Nested loops
    • 5.4 Break and continue
    • 5.5 Loop else
    • 5.6 Chapter summary
  • 6 Functions
    • Introduction
    • 6.1 Defining functions
    • 6.2 Control flow
    • 6.3 Variable scope
    • 6.4 Parameters
    • 6.5 Return values
    • 6.6 Keyword arguments
    • 6.7 Chapter summary
  • 7 Modules
    • Introduction
    • 7.1 Module basics
    • 7.2 Importing names
    • 7.3 Top-level code
    • 7.4 The help function
    • 7.5 Finding modules
    • 7.6 Chapter summary
  • 8 Strings
    • Introduction
    • 8.1 String operations
    • 8.2 String slicing
    • 8.3 Searching/testing strings
    • 8.4 String formatting
    • 8.5 Splitting/joining strings
    • 8.6 Chapter summary
  • 9 Lists
    • Introduction
    • 9.1 Modifying and iterating lists
    • 9.2 Sorting and reversing lists
    • 9.3 Common list operations
    • 9.4 Nested lists
    • 9.5 List comprehensions
    • 9.6 Chapter summary
  • 10 Dictionaries
    • Introduction
    • 10.1 Dictionary basics
    • 10.2 Dictionary creation
    • 10.3 Dictionary operations
    • 10.4 Conditionals and looping in dictionaries
    • 10.5 Nested dictionaries and dictionary comprehension
    • 10.6 Chapter summary
  • 11 Classes
    • Introduction
    • 11.1 Object-oriented programming basics
    • 11.2 Classes and instances
    • 11.3 Instance methods
    • 11.4 Overloading operators
    • 11.5 Using modules with classes
    • 11.6 Chapter summary
  • 12 Recursion
    • Introduction
    • 12.1 Recursion basics
    • 12.2 Simple math recursion
    • 12.3 Recursion with strings and lists
    • 12.4 More math recursion
    • 12.5 Using recursion to solve problems
    • 12.6 Chapter summary
  • 13 Inheritance
    • Introduction
    • 13.1 Inheritance basics
    • 13.2 Attribute access
    • 13.3 Methods
    • 13.4 Hierarchical inheritance
    • 13.5 Multiple inheritance and mixin classes
    • 13.6 Chapter summary
  • 14 Files
    • Introduction
    • 14.1 Reading from files
    • 14.2 Writing to files
    • 14.3 Files in different locations and working with CSV files
    • 14.4 Handling exceptions
    • 14.5 Raising exceptions
    • 14.6 Chapter summary
  • 15 Data Science
    • Introduction
    • 15.1 Introduction to data science
    • 15.2 NumPy
    • 15.3 Pandas
    • 15.4 Exploratory data analysis
    • 15.5 Data visualization
    • 15.6 Summary
  • Answer Key
  • Index

Book details

  • Title: Introduction to Python Programming
  • Author(s): Udayan Das; Aubrey Lawson; Chris Mayfield; Narges Norouzi (Senior Contributing Authors)
  • Main category: Programming
  • Subcategory: Python
  • Language: English
  • License: Creative Commons Attribution 4.0 International (CC BY 4.0)

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.