I. Python Programming
Introduction to Python & Programming
| Order | File Name | Comments |
|---|---|---|
| 1 | What is programming and Python | Brief notes on what is programming and python, as well as an overview of thee computer architecture. |
| 2 | Types of Errors | Understanding syntax, logic, and semantic errors. |
| 4 | Python Variables | Overview of Python variables, how to assign values to a variable, and naming convention. |
| 5 | Python Data Types | Overview of basic Python data types (numeric, string, collection, and boolean). |
| 6 | Python Iterables | Iterable objects in Python (lists, dictionary, tuples) |
| 7 | Python Indexing and Slicing | How to retrieve elements in an `iterable object` using **indexing**. |
| 8 | Python Comments | Commenting code using `#` and creating multi-line comments. |
| 9 | Debugging Tips | Tips on test cases and using python's `assert` statement. |
| 10 | Copying in Python and Aliasing | Understanding shallow vs deep copies in Python and why you should not use the assignment operator for copying mutable objects. |
| 11 | Common Keywords and Operators | Operators: `in`, `not in`, `is`, `is not`. Keyword definitions: `None`. |
| 12 | Python Modules and Libraries | What are python libraries, and how to import modules. Renaming modules with an alias. |
| 13 | Type Conversions | Implicit vs explicit type conversions. |
Python Data Types
| Order | File Name | Comments |
|---|---|---|
| 1 | Boolean Values and Expression | Types of Boolean Expression and Evaluating Booleans |
| 2 | Python Strings | What are strings, common methods and operations, reversing strings, string comparisons, and string formats. |
Python Data Structures
What is the difference between data type and data structure?
Data Type:
- Refers to the category of data that a variable can hold
Data Structure:
- Refers to the method of organizing and storing data in a computer's memory or storage system, as well as manipulation of that data.
Data structures in Python are built-in or user-defined structures that allow you to store, organize, and manipulate data efficiently. There are 4 main types of built-in data structures[1] in python.
Summary of Python built-in data structures:
| Data Structure | Definition | Ordered | Mutable | Allows Duplicates | Key-Value Pairs | Unique Elements |
|---|---|---|---|---|---|---|
| List | Ordered collection of elements | Yes | Yes | Yes | No | No |
| Dictionary | Unordered collection of key-value pairs | No | Yes | Keys: No, Values: Yes | Yes | No |
| Set | Unordered collection of unique elements | No | Yes | No | No | Yes |
| Tuple | Ordered collection of elements | Yes | No | Yes | No | No |
Python Lists
Using Lists as an Argument for a Parameter
When you pass a list into a function, the function gets a reference to the list (not a copy). Since lists are mutable, any changes made to the elements referenced in that parameter of a function will change the original list. Important to create a new list: new_list = old_list[:]
| Order | File Name | Comments |
|---|---|---|
| 1 | Creating a List | Creating an empty list using `[]` and `list()` constructor method. |
| 1 | About Python Lists | What is a python list? How do we create a list and retrieve elements in a list? |
| 3 | Changing Elements in a Lists | How to change all and specific elements of a Python List. |
| 4 | Copying Lists | How to avoid "aliasing" when copying lists where you have multiple variables referencing the same object in memory. Want to create an independent copy of the list using `copy()` or slicing. |
| 5 | List Comprehension | Short-handed notation for creating a new list based on an existing iterables. |
| 6 | Concatenating Lists | Concatenating lists using the `+` operator or the `extend()` method. |
| 9 | Multidimensional (Nested) Lists | Overview and how to create a user-defined matrix and how to index for specific elements. |
Lists Methods
List of List Methods
To get a, we can run the following: dir(list) to get a list of methods
| Order | File Name | Comments |
|---|---|---|
| 1 | Adding Elements in a List | Methods used to add elements in a list: `append()`, `insert()`. |
| 2 | Removing Elements in a List | Methods used to remove elements in a list: `remove()`, `pop()`, and `del()`. |
| 3 | `Insert()` Method | How to insert an element at a specified position in a list. Basic Syntax for the `insert()` method. |
| 4 | `sort()` Method | Sorting a list "in-place", without creating a new list. |
| 5 | `sorted()` Method | Create a new sorted list from an existing list. Does not sort "in-place". |
| 6 | `join()` Method |
Python Dictionaries
| Order | File Name | Comments |
|---|---|---|
| 1 | About Python Dictionaries | How to create an instance of a `dictionary` and clear a dictionary. |
| 2 | Accessing Key and Values in a Dictionary | Accessing key/values in a dictionary using the `get()`, `items()`, 'keys()` and `values()`. |
| 3 | Adding and Removing Items | How to modify, add, or remove a key-value pair in a dictionary. |
| 4 | Sorting a Dictionary | How to sort by keys and values within a dictionary, and custom sorting with `lambda` functions. |
| 5 | Counting Using Dictionaries | How to use a dictionary to count items. Sample syntax. |
| 6 | Counting Occurrence of Words in a Text File | How to use dictionaries to count the occurrence of words in a text file. |
| 7 | Indexing a Nested List | How to index values of a nested dictionary by its key. |
| 8 | Looping Through Dictionaries | Iterating through dictionaries by `key`, `value`, or `key:value` pair. |
Python Tuples
| Order | File Name | Comments |
|---|---|---|
| 1 | About Python Tuples | Tuples are essentially unmodified versions of a `List`. Once created, it cannot be changed. As a result, there are no methods that can add or remove items in a tuple. |
| 2 | Accessing Tuple Elements | Indexing and slicing elements in a tuple. |
| 3 | Tuple Unpacking (Multiple Assignment) | How to assign values to multiple variables in a single line. Can be used in conjunction with tuples, lists, or other iterable types. |
Python Sets
| Order | File Name | Comments |
|---|---|---|
| 1 | About Python Sets | Based on set theory. |
| 2 | Set Union | Using sets and the `union()` method to retrieve the unique elements of 1 or more iterable objects. |
| 3 | Set Intersection | How to retrieve elements that exists in 1 or more iterable objects. |
| 4 | Set Difference | Retrieving elements found exclusively in one specified set. |
| 5 | Superset and Subsets | Comparing relationships between sets with respect to `superset` and `subset`. |
| 6 | Symmetric Difference | Set difference returns only the elements not found in se |
Python Functions
| Order | File Name | Comments |
|---|---|---|
| 1 | About Python Functions | How to call functions, passing arguments in a function, and the 2 main types of function: (1) User-defined functions, and (2) built-in functions. |
| 2 | User-Defined Functions & Type Annotations | General structure of defining your own function and type annotations in specifying the function's parameter type and return type. |
| 3 | Lambda Expressions | Anonymous functions with `lambda` expressions. |
| 4 | Docstrings | Creating string literals that appear right after the definition of a function (also applicable to method, class, or a module). |
| 5 | Function Compositions | Concept of combining two or more functions to create a new function, where the output of one function becomes the input for another. |
| 6 | Nested Function | Concept of defining a function within another function and definitions of `local`, `nonlocal`, and `global` variables in the context of accessing variables. |
| 7 | Local and Global Variables | Summary of local, nonlocal, and global variables. |
| 8 | Arguments and Parameters | Parameter is the variable defined in a function. Argument is the value that is passed through the function when it is called, assigned to the corresponding parameter defined inside the function. |
| 9 | Return Values | Using the `return` keyword to pass the result or value of a function invoked back to the caller. A function with a return statement is referred to as a "fruitful" function. |
Python Loops
| Order | File Name | Comments |
|---|---|---|
| 1 | About Python Loops | Overview of for and while loops, how the number of iterations are defined. |
| 2 | For Loop | Understanding the structure and flow of a for loop and how to create a for loop. |
| 3 | While Loops | Structure and flow of execution for a while loop. Also how to execute while loops without a boolean expression. |
| 4 | Keywords Within Loops | `Break`, `Continue` keywords to exit out of the loop or skip to the next iteration of the loop. |
| 5 | Infinite Loops | What happens when the while loop always evaluates to `True`. |
| 6 | Input-Controlled Loops | Controlling while loops based on user-input. |
Python Conditionals
| Order | File Name | Comments |
|---|---|---|
| 1 | About Python Conditional Statements | |
| 2 | Logical Connectives (Operators) | Brief overview of `AND`, `OR`, and `NOT` logical connective and corresponding truth table. |
| 4 | The IF Statement | Basic structure of one-way IF statements and why **indentation** is important. |
| 5 | The IF-ELSE Statement | Constructing a Two-Way IF Statement |
| 6 | The IF-ELIF-ELSE Statement | If statements for more than 2 possible outcomes. |
| 7 | Nested Conditions | Creating nested conditions under `IF` or `ELSE` block. |
| Comparison Operators |
Python Classes & Inheritance
| Order | File Name | Comments |
|---|---|---|
| 1 | About Python Classes and Inheritance | Definitions for class and inheritance, and understanding attributes and behaviours of a class. |
| 2 | Creating a Class | How define the class structure, its methods and attributes. Constructing an instance of the class by calling the class. |
| 3 | Class vs Instance Variables | How to define variables shared among ALL class vs variables specific to an instance of the object. |
| 4 | The __init__() Constructor Function | More information on the constructor function |
| 5 | Class Inheritance | How to create a class that inherits all the methods and properties of another class (parent). Does **not** introduce their own. |
| 6 | Creating Subclasses | How to create a child class that inherits all the parent properties and methods, but also introduces its own properties and methods. How to override a parent method. |
Python Try-Except
| Order | File Name | Comments |
|---|---|---|
| 1 | About Try-Except | How to deal with run-time error using `Try/Except` without the program crashing. |
| 2 | Raising an Exception | Using the `raise` exception statement to signal a run-time error has occurred during the execution of the program. Often used for handling edge cases or for testing scenarios where you may intentionally raise an exception. |
| 3 | Additional Keywords | `Else` to define a block of code to be executed if no errors were raised. `Finally` to define a block of code to be executed regardless of whether an error is raised or not. |
Python File Handling
| Order | File Name | Comments |
|---|---|---|
| 1 | About Python File Handling | Overview of how to open and read files. |
| 2 | Getting the File | What to do if the file is not in the same directory as the Python program and how to get the file path. |
| 3 | Writing to a File | Writing to a file in `w` or `a` mode using `write()` or `writelines()`. |
| 4 | Closing a File | Closing a file. |
| 5 | File Handling Using With | |
| 6 | Exporting to a File | Exporting a DataFrame to a particular file (CSV, xlsx, JSON, parquet, to a SQL database) |
Useful Miscellaneous Codes
| Order | File Name | Comments |
|---|---|---|
| 1 | User Input | How to prompt users for an input. |
| 2 | The Zip() Function | How to combine elements from two or more iterable objects based on their corresponding positions. |
| 3 | The Map() and Filter() Function | Using `map()` to apply a function to each element in a iterable. Using `filter()' to filter for elements in an iterable based on the result of a function applied. |
A data structure refers to a way of organizing and storing data in a computer's memory or storage system. ↩︎