Security scan is checking this page.

OpenStax books

Introduction to Python Programming

A short summary of each chapter, then the key terms that chapter names. Each chapter link opens that chapter in the OpenStax book.

Open the book

Chapter 1

Statements

Read chapter 1 in the book

Summary

At this point, you should be able to write programs that ask for input, perform simple calculations, and output the results. The programming practice below ties together most topics presented in the chapter If present, prompt is output to the user. The function then reads a line of input from the user

Chapter 2

Expressions

Read chapter 2 in the book

Summary

Expressions and statements can be run interactively using a shell Input strings can be converted to other types. Strings can be concatenated with other types.

Chapter 3

Objects

Read chapter 3 in the book

Summary

A string is a sequence of values that represents Unicode code points An index refers to the position of a value in a sequence (string, list, tuple) F-strings are a convenient way to print multiple outputs and format integers and floats

Key terms

string
a sequence of values that represents Unicode code points

Chapter 4

Decisions

Read chapter 4 in the book

Summary

Booleans represent a value of True or False Comparison operators compare values and produce True or False Logical operators take condition operand(s) and produce True or False

Chapter 5

Loops

Read chapter 5 in the book

Summary

A loop else statement runs after the loop's execution is completed without being interrupted by a break statement A break statement is used within a for or a while loop to allow the program execution to exit the loop once a given condition is triggered A while loop runs a set of statements, known as the loop body, while a given condition, known as the loop expression, is true

Key terms

break statement
used within a for or a while loop to allow the program execution to exit the loop once a given condition is triggered
loop's execution
completed without being interrupted by a break statement

Chapter 6

Functions

Read chapter 6 in the book

Summary

Functions are named blocks of code that perform tasks when called and make programs more organized and optimized Control flow is the sequence of program execution. Control flow moves between calling code and function code when a function is called

Chapter 7

Modules

Read chapter 7 in the book

Summary

Modules often include the line if __name__ == "__main__" to prevent code from running as a side effect when the module is imported by other programs When working in a shell, the help () function can be used to look up the documentation for a module. The documentation is generated from the docstrings

Key terms

documentation
generated from the docstrings
side effect when the module
imported by other programs

Chapter 8

Strings

Read chapter 8 in the book

Summary

Logical operators can be used to compare two string values. String comparison is done by comparing corresponding ASCII values of characters in the order of appearance in the string String indexing is used to access a character or a sequence of characters in the string

Key terms

string
a sequence of characters

Chapter 9

Lists

Read chapter 9 in the book

Summary

The copy() method is used to create a copy of a list Lists are mutable and can be easily modified by using append() , remove() , and pop() operations Lists are iterable and can be iterated using an iterator or element indexes The sort() operation arranges the elements of a list in ascending order if all elements of the list are of the same type

Key terms

copy() method
used to create a copy of a list

Chapter 10

Dictionaries

Read chapter 10 in the book

Summary

A dictionary in Python is a container object including key-value pairs The dict type implements a dictionary in Python A dictionary is a mutable object but keys in the dictionary must be immutable objects

Key terms

dictionary
a mutable object but keys in the dictionary must be immutable objects
dictionary in Python
a container object including key-value pairs

Chapter 11

Classes

Read chapter 11 in the book

Summary

Instances of a class type represent objects and are created using __init__() Object-oriented programming involves grouping related fields and procedures into objects using data abstraction and encapsulation Classes define a type of object with attributes and methods

Key terms

class type represent objects and
created using __init__()

Chapter 12

Recursion

Read chapter 12 in the book

Summary

Demonstrate how recursion uses simpler solutions to build a bigger solution Demonstrate how to compute a recursive solution for the factorial function Demonstrate the use of recursion to solve a string problem

Chapter 13

Inheritance

Read chapter 13 in the book

Summary

Inheritance describes an is-a relationship between classes. One class, the subclass, inherits from another class, the superclass Subclasses can access inherited attributes and methods directly

Chapter 14

Files

Read chapter 14 in the book

Summary

Exceptions that cause a program to terminate can be handled using try and except Raising an exception is an alternative way to return from a function when an error occurs

Key terms

exception
an alternative way to return from a function when an error occurs

Chapter 15

Data Science

Read chapter 15 in the book

Summary

The data science life cycle is the framework followed by data scientists to complete a data science project The data science life cycle includes 1) data acquisition, 2) data exploration, 3) data analysis, and 4) reporting Data science is a multidisciplinary field that combines collection, processing, and analysis of large volumes of data to extract insights and drive informed decision-making

Key terms

data science life cycle
the framework followed by data scientists to complete a data science project

Summaries and key terms on this page are taken from that chapter’s material already kept for this desk. They follow the OpenStax book. Margins is not affiliated with OpenStax. Resources, policy, and site safety