Python Tricks You Should Know¶
by Cameron Kleiman, Spring 2023
This document is intended as an unofficial guide for MIT 6.101 (formerly 6.009) students to give you some handy Python functions and tricks as you go about your 6.101 labs. The hints here will help make your life easier as you go about developing your solutions to the labs.
They won't help you with the labs directly, but they'll improve your Python developer experience to help you write better, more efficient code that you can understand. Without further ado, here's Python Tricks You Should Know.
This document is a largely unedited draft. If you have feedback or comments on this guide, please leave issues/PRs on GitHub at this link or email me at email@example.com.
This guide contains a few sections on different topics that will be more or less relevant in 6.101, but also in your software projects in the future. Here's an overview of this guide:
- General Advice - General advice for beginners of programming on writing and debugging code.
- Useful Functions - A wide variety of built-in functions that will come in handy in 6.101
- Trick Sheet - Simple, handy Python tricks that you can use to elegantly check or manipulate data
- Editing Python - Python-specific code style and editing tips
- Comprehensions - An overview of Python's powerful comprehension feature
- Avoid This - Some common pitfalls to avoid or watch out for as you write Python for 6.101
The Useful Functions and Comprehensions sections are more code-heavy, while the General Advice and Editing Python sections contain more advice.
You're welcome to skip around and read the parts that interest you or read it top-to-bottom, whatever you like. Some of these sections might be more useful after you've done a few labs in 6.101, so feel free to skim and check back later once you've made some more progress.
Python Standard Library¶
Many parts of this guide contain links to the Python Standard Library reference. This reference contains the authoritative documentation on the built-in functions and data types that you'll use in 6.101. I highly recommend using this resource if you want to learn more about them from the official manual.
This guide, which includes all pages under this section, is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Feel free to copy or adapt it for your own Python course materials!