Programming in Python
This is an online textbook on Python and is a companion resource to the course Programming in Python
offered as a part of the Online Degree Program, IIT-Madras. For more details about the course, check out our website.
Note to students: This book is meant to be used as a reference. You may find content that has not been covered in the video lectures. Likewise, there may be some content that is present in the lectures which is not covered here. Additional content appearing in this book will not be considered for grading. In summary, please refer to chapters that you feel are relevant for the course. But you are under no obligation to read the entire book cover to cover. Interested students are always welcome to read the entire thing!
Chapter-0: Warm-up
Chapter-1: Introduction to Python
- Python shell | Replit Console
- Prompts | Output
- Emojis
- Literals and Variables
- Basic Data types | type()
- Comments
- Operators
- Convention
- Expressions
- Type of Expressions
- Arithmetic Expressions
- Boolean Expressions
- Replit Editor
- Errors | Debugging
- Exceptions
- Wrong Code Snippets
- Strings
- Quotes
- Length
- Operations
- Escape Characters
- Substrings
- Strings
- Indexing
- Slicing
- Immutability
- Methods
Chapter-2: Conditionals
- Variables | Assignment operator | Dynamic Typing
- Referencing versus Defining | Keywords and Naming Rules
- Reusing Variables | Multiple Assignment | Deleting Variables
- Input
- Type Conversion | Built-in Functions
- Conditional Statements
if
if-else
if-elif-else
- Nested Conditional Statements
- Defining Variables inside
if
- System libraries
calendar
time
this
Chapter-3: Loops
while
loopbreak
,continue
for
looprange()
- Iterating through Strings
- Nested loops
while
versusfor
print
end
sep
- Formatted printing
- f-strings
format()
- Format Specifiers
System libraries
math
random
Mathematics and Programming
- Limits
- Recurrence relations
- Rational approximation
Chapter-4: Functions
- Introduction
- Examples
- Arguments
- Positional Arguments
- Keyword Arguments
- Default Arguments
- Call by Value
- Scope
- Local
- Global
- Namespaces
- locals
- globals
- Scope and Namespaces
- Recursion
- Caution in Recursion
Chapter-5: Lists and Tuples
- Lists
- Introduction
- Iterating through Lists
- Growing a List
- Operations on Lists
- Useful Functions
- Lists
- Mutability
- Call by Reference
- Lists
- Simulating an IPL Innings
- Lists
- List Methods
- Stack and Queue
- Strings and Lists
split
join
- Lists
- Nested Lists
- Matrices
- Shallow and Deep Copy
- Tuples
- Introduction
- More on Tuples
- Lists and Tuples
- Packing and Unpacking
Chapter-6: Dictionaries and Sets
- Dictionaries
- Introduction
- Examples
- Iterating over Dictionaries
- Growing a Dictionary
- Mutability
- Text Processing
- Number of Sentences
- Number of Words
- Number of Unique Words
- Frequent Words
- Dictionaries
- Pangrams and Dictionaries
- Dictionary Methods
- Dictionaries in Action: LMS
- Assignment Model
- Submission Model
- Grader
- Sets
- Introduction
- Iterating over Sets
- Growing Sets
- Set Operations
Chapter-7: File Handling
- File Handling
- Why Files
- File Handling
- File Handling
- Creating a file in Replit
- Opening and Reading from a file
- Writing to a file
- File Handling
- File object analogy
- Mode
- File Handling
- File methods
read
readline
readlines
write
writelines
- File Handling
- CSV files
- Reading a CSV file
- Files to Collections
Chapter-8: Object Oriented Programming
- Objects and Classes
- OOP in Python: an example
- Classes and Objects
self
- Class Attributes vs Object Attributes
- Inheritance
- Concrete Example
- Parent-child relationship
- Method Overriding
- Vector: Mathematical Preliminaries
- Vector: Specification
- Vector: Definition
- Collection of Vectors