A.7: Python

Learning Objectives

  1. Python is more commonly used than JavaScript for data and algorithm-related work due to its built-in data manipulation libraries and simpler syntax

  2. Learn basic Python syntax to be able to use Python for algorithm problems that are easier solved with Python's built-in libraries, such as algorithms involving queues and heaps

Introduction

Python is commonly used in data and algorithm-related work due to its built-in data manipulation libraries and simpler syntax. Luckily, Python is conceptually very similar to JavaScript, and most translations from Python to JavaScript and vice versa are purely syntactical translations.

This submodule aims to help us learn Python through exercises to solve algorithm problems that are easier solved with Python, such as algorithms involving queues and heaps.

Python Quirks

  1. Python variables adhere to function scope, which means all local variables are accessible within the function in which they are declared. This is different from the block scope that applies to let and const vars in JavaScript.

  2. Python == works like JS ===, in that both operators compare both value and data type.

Exercises

The following are a collection of concise exercises from learnpython.org (powered by datacamp.com) that we believe will be helpful in learning Python for algorithms.