Skip to content

Logo

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

Lesson-0

Chapter-1: Introduction to Python

Lesson-1.1

  • Python shell | Replit Console
  • Prompts | Output
  • Emojis
  • Literals and Variables
  • Basic Data types | type()
  • Comments

Lesson-1.2

  • Operators
  • Convention
  • Expressions
  • Type of Expressions

Lesson-1.3

  • Arithmetic Expressions
  • Boolean Expressions

Lesson-1.4

  • Replit Editor
  • Errors | Debugging
  • Exceptions
  • Wrong Code Snippets

Lesson-1.5

  • Strings
  • Quotes
  • Length
  • Operations
  • Escape Characters
  • Substrings

Lesson-1.6

  • Strings
  • Indexing
  • Slicing
  • Immutability
  • Methods

Chapter-2: Conditionals

Lesson-2.1

  • Variables | Assignment operator | Dynamic Typing
  • Referencing versus Defining | Keywords and Naming Rules
  • Reusing Variables | Multiple Assignment | Deleting Variables

Lesson-2.2

  • Input
  • Type Conversion | Built-in Functions

Lesson-2.3

  • Conditional Statements
  • if
  • if-else
  • if-elif-else
  • Nested Conditional Statements
  • Defining Variables inside if

Lesson-2.4

  • System libraries
  • calendar
  • time
  • this

Chapter-3: Loops

Lesson-3.1

  • while loop
  • break, continue

Lesson-3.2

  • for loop
  • range()
  • Iterating through Strings

Lesson-3.3

  • Nested loops
  • while versus for
  • print
  • end
  • sep

Lesson-3.4

  • Formatted printing
  • f-strings
  • format()
  • Format Specifiers

Lesson-3.5

System libraries

  • math
  • random

Lesson-3.6

Mathematics and Programming

  • Limits
  • Recurrence relations
  • Rational approximation

Chapter-4: Functions

Lesson-4.1

  • Introduction
  • Examples

Lesson-4.2

  • Arguments
  • Positional Arguments
  • Keyword Arguments
  • Default Arguments
  • Call by Value

Lesson-4.3

  • Scope
  • Local
  • Global
  • Namespaces
  • locals
  • globals
  • Scope and Namespaces

Lesson-4.4

  • Recursion
  • Caution in Recursion

Chapter-5: Lists and Tuples

Lesson-5.1

  • Lists
  • Introduction
  • Iterating through Lists
  • Growing a List
  • Operations on Lists
  • Useful Functions

Lesson-5.2

  • Lists
  • Mutability
  • Call by Reference

Lesson-5.3

  • Lists
  • Simulating an IPL Innings

Lesson-5.4

  • Lists
  • List Methods
  • Stack and Queue
  • Strings and Lists
    • split
    • join

Lesson-5.5

  • Lists
  • Nested Lists
  • Matrices
  • Shallow and Deep Copy

Lesson-5.6

  • Tuples
  • Introduction
  • More on Tuples
  • Lists and Tuples
  • Packing and Unpacking

Chapter-6: Dictionaries and Sets

Lesson-6.1

  • Dictionaries
  • Introduction
  • Examples
  • Iterating over Dictionaries
  • Growing a Dictionary
  • Mutability

Lesson-6.2

  • Text Processing
  • Number of Sentences
  • Number of Words
  • Number of Unique Words
  • Frequent Words

Lesson-6.3

  • Dictionaries
  • Pangrams and Dictionaries
  • Dictionary Methods

Lesson-6.4

  • Dictionaries in Action: LMS
  • Assignment Model
  • Submission Model
  • Grader

Lesson-6.5

  • Sets
  • Introduction
  • Iterating over Sets
  • Growing Sets
  • Set Operations

Chapter-7: File Handling

Lesson-7.1

  • File Handling
  • Why Files
  • File Handling

Lesson-7.2

  • File Handling
  • Creating a file in Replit
  • Opening and Reading from a file
  • Writing to a file

Lesson-7.3

  • File Handling
  • File object analogy
  • Mode

Lesson-7.4

  • File Handling
  • File methods
    • read
    • readline
    • readlines
    • write
    • writelines

Lesson-7.5

  • File Handling
  • CSV files
    • Reading a CSV file
    • Files to Collections

Chapter-8: Object Oriented Programming

Lesson-8.1

  • Objects and Classes
  • OOP in Python: an example

Lesson-8.2

  • Classes and Objects
  • self
  • Class Attributes vs Object Attributes

Lesson-8.3

  • Inheritance
  • Concrete Example
  • Parent-child relationship
  • Method Overriding

Lesson-8.4

  • Vector: Mathematical Preliminaries
  • Vector: Specification
  • Vector: Definition
  • Collection of Vectors