Momentum logo
Team 3 Classroom

Python Sequences and Files

Posted on Aug 11th, 2020

We can use the generic term sequence for any object that provides an ordered structure for a number of items, such as a string (a group of characters), a list, or a dictionary (keys and values).

Today’s topics

  • Bread & butter sequence types: list, str, tuple, and dict
  • Basic sequence keywords and operations: for and in
  • Working with files

Tomorrow’s topics

  • Advanced indexing and slicing
  • Comprehensions for lists, dicts, and generators
  • Important sequence methods

🐍 Code Breaks

Try working with lists Practice with list comprehensions

Projectm

You’ll be doing this assignment for the next two days, and we’ll work on parts of it in class.

Word Frequency

Resources

Welcome to Phase 2: Intro to Back-End Development with Python 🐍

Posted on Aug 10th, 2020

In Phase 2 we’ll learn about…

  • Python
  • Django and back-end web development
  • Databases
  • Deploying Django applications

Today’s topics

  • What is backend development?
  • Running Python
  • Syntax differences between JS and Python
  • Python
    • variables
    • if statements
    • while loops
    • Input and output with input and print
    • Functions

🐍 Code Break

Try working with input and output

Project

We’ll begin Python the way we began JavaScript, with some exercises and tests you can run to keep you on track. We’re going to use an awesome free online tool called Exercism.

Please sign up (you can use your GitHub account) and choose the Python track. There are two ways to use Exercism, in Practice Mode or Mentor Mode. It’s up to you which you choose.

Work through the setup instructions to install Exercism on your computer with Homebrew. In the Python track, complete the following exercises:

  1. Hello World
  2. Raindrops
  3. Hamming

For each exercise, follow the instructions on Exercism to upload your solution.

To submit your homework, paste your solution urls into this form.

If you get through all three of these, please continue with other exercises that seem fun to you. There are lots to choose from!

Resources

Tags: phase-2 python

Phase 2 Syllabus, Part 1

Posted on Aug 10th, 2020

As requested, here’s a master syllabus for this phase, up to our introduction to Django. I hope to have the Django syllabus up later this week. I will also be releasing separate syllabi for advanced Python topics (many of which I’ll likely cover in class as time permits) and very advanced topics (I will likely not cover these in great detail, but I hope they can provide a good roadmap if you plan to study Python further).

A note on dates

These dates are speculative/ideal. We may cover more than is indicated here (but not less), at a faster or slower pace, depending on how things go.

Monday, August 10th

  • Introduction to backend programming
  • Introduction to Python
    • differences between Python 2 and Python 3
    • variables
    • arithmetic expressions
    • simple statements: if, while, and def
    • input and output: input() and print

Tuesday, August 11th and Wednesday, August 12th

  • Introduction to sequences
    • sequence types: list, tuple, str, and dict
    • sequence keywords: for, in
    • indexing and slicing
  • Introduction to files
    • basics: open, read, write
    • file modes: “r”, “w”, “a”, “r+”, “w+”, “a+”
    • context managers: with, as
    • treating files as sequences

Thursday, August 13th

  • modules and importing
    • the import keyword
  • exceptions
    • creating exceptions: raise and Exception
    • dealing with exceptions: try and except
  • using modules to structure big projects

Monday, August 17th

  • Object-oriented programming (OOP)
    • What is an object?
    • attributes (data)
    • methods (behavior)
    • inheritance (don’t repeat yourself)
    • instances and classes
  • Object-oriented programming in Python with class
    • class quirks: understanding self and __init__
    • defining methods
    • creating subclasses

Tuesday, August 18th

  • What are packages?

  • PyPi, pip, and pipenv

  • Web application frameworks

  • Introduction to Django

    • What is Django?
    • Structure of Django projects
    • Models, Views, and Templates in django projects

Python Checklist for Monday

Posted on Aug 7th, 2020

Great work these last four weeks, y’all. You should take a well-earned break this weekend, but I wanted to post two simple things for y’all to do to be prepared to start Python on Monday. I’d like you to try the first two, but don’t stress if you can’t get it to work, and don’t spend too much time on it – we’ll sort it out on Monday before class begins.

Things to do for Monday

Install exercism

Open a terminal and enter the following command verbatim (the && chains commands together, but only if the first one doesn’t fail): brew update && brew install exercism

Exercism is a great tool we’ll be using for doing warmup and learning exercises.

Install pipenv

Open a terminal and enter the following command verbatim: brew install pipenv

pipenv is a package management tool that will simplify the task of organizing complex Python projects.

Get to know Python

I’m including a few links to good beginner resources for anyone who’s eager to get started.

-Real Python Python Basics -Official Python Beginner’s Resources -Official Python Tutorial -Python Library & Language Documentation (bookmark this site)

Quick note on Python 2 vs Python 3

There are two major versions of Python in common use – Python 2 and Python 3. Python 2 is no longer updated and support is being withdrawn, but because MacOS uses Python 2 in a few places, Python 2 is the default version. This is annoying and complicates things somewhat, but isn’t too difficult to navigate around – if you’re trying out code you found on the internet, and it says (for example): python a_python_script.py

you should instead run: python3 a_python_script.py

There are a couple of other places where you may need to run slightly different commands, but I’ll only go over one of them right now; if you try some of the exercism.io exercises this weekend, it may tell you to run: pytest hello_world_test.py

Instead, you should run: python3 -m pytest hello_world_test.py

(of course, hello_world_test.py could be any Python file).