• Stars
    star
    488
  • Rank 89,583 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Exercises and code snippets to share with my students

First time installing/running Python? Be sure to check out the Start Here guide: https://github.com/shannonturner/python-lessons/blob/master/start-here.md

In here are code snippets, examples, and other ways to help teach some of the concepts and tricks in Python.

Slides are available to download here: https://github.com/hearmecode/slides

Suggested Learning Progression

If you're new to Python you may wonder what you should learn and when you should learn it. I recommend this order seen below. Each section below has its own folder above; each bullet point has its own file within that folder.

So if you wanted to learn more about variable assignment, go to the folder section_01_(basics) and open up variable_assignment.py

Section 1: General Programming Basics

  • Simple Math
  • Variable Assignment
  • Basic Syntax and Logic
  • Data Types: int, float, bool, str

Section 2: Strings

  • Identifying and using strings
  • String slicing
  • String formatting
  • String methods
    • str.replace()
    • str.find()
    • str.count()
    • str.lower()

Section 3: Conditionals

  • Logical control; changing the behavior of your programs
  • and keyword, or keyword
  • if / else structure
  • if / elif ... / else structure
  • Nesting conditionals

Section 4: Lists

  • Containers for data types
  • First In, Last Out (Stack)
  • Accessing specific list items through index (slice notation)
  • List methods
    • list.append()
    • list.insert()
    • list.pop()
    • list.extend()
  • Finding items in list (in keyword)
  • Deduplicating a list using list(set(list_to_deduplicate))

Section 5: Loops

  • for loop (for each item in a list: ...)
  • enumerate()
  • zip()
  • range()
  • while loop (ask each time: is this still true?)

Section 6: Strings to Lists and Vice-Versa

  • str.join() (create a string from a list)
  • str.split() (create a list from a string)

Section 7: File handling

  • with open(filename) as textfile: ...
  • file.read()
  • Reading text files
  • Reading CSV files
  • File handling flags (r, w, b, +)
  • Writing to files

Section 8: Python's Most Commonly Used Built-in Functions

    • Types (used primarily for converting one type to another)
  • int()
  • float()
  • str()
  • bool()
  • list()
  • set()
  • dict()
    • Comparison and Calculation
  • abs()
  • len()
  • max()
  • min()
  • round()
  • sum()
    • Loop (Sequence) Control
  • enumerate()
  • range() / xrange()
  • reversed()
  • sorted()
  • zip()

Section 9: Functions

  • def keyword
  • arguments
  • default arguments
  • *args
  • **kwargs
  • return keyword
  • sequence unpacking (return and receive multiple values)
  • namespaces

Section 10: Dictionaries

  • Accessing specific dictionary items through key (looks like a slice)
  • Accessing all keys as a list using .keys()
  • Faking a sorted dictionary by using sorted() on the .keys()
  • Accessing all values as a list using .values()
  • Accessing all key, value pairs as a list using .items()
  • Adding new items through .fromkeys()
  • Checking for whether a key exists with .has_key
  • Using .get() to safely get a key's value if it exists without getting an error if not
  • Adding new items with direct assignment and .update()

Section 11: Dictionaries and Lists, together

  • Accessing specific items in a nested list
  • Accessing specific items in a nested dictionary
  • Accessing specific items in a nested list within a dictionary
  • Accessing specific items in a nested dictionary within a list
  • If you can do those four above, you can handle receiving JSON API returns

Section 12: Standard Library

  • import keyword
  • from ... import ... as ... structure
  • time
  • random
  • math
  • re (regular expressions)
  • os
  • sys
  • json

Section 13: External Libraries (Not necessarily in order; keep these in mind)

  • Installing external libraries with easy_install
  • Using easy_install to install pip (an easier / better way to install external libraries)
  • requests (web crawling made easy)
  • BeautifulSoup (parsing HTML)
  • xlrd (Read Excel .xls files)
  • xlwt (Write to Excel .xls files)
  • xlsxwriter (Write to Excel .xls and .xlsx files, with additional functionality beyond xlwt)
  • cherrypy (Simple, lightweight framework for serving web pages)
  • psycopg2 (Connect to and issue SQL commands to your postgresql database)

Section 14: Exception Handling

  • try / except syntax
  • Using multiple excepts
  • Recognizing the different error types
  • Exception, the generic exception type (use sparingly)
  • Nesting exception handling
  • try / except / else syntax

Section 15: Intermediate Concepts

  • List Comprehensions
  • Inline Conditionals
  • Generators

Section 16: Classes

  • Classes
  • Magic Methods

More Repositories

1

metro-map-maker

Build the Metro system of your dreams: create your own metro maps, save them, and share with friends!
Python
53
star
2

bechdel

If your movie doesn't pass the Bechdel test, we'll find you a better one
Python
20
star
3

html-table-to-excel

Python functions to convert an HTML table to an Excel (.xls) file.
Python
15
star
4

shut-that-down

Offensive quotes by politicians and the corporations who fund them
HTML
13
star
5

secret

Free yourself from the burden of your secrets
HTML
8
star
6

text-to-bitmap

Encodes your secret message or file as an image
Python
8
star
7

art-games

Games to discover new art and artists using museum APIs
Python
7
star
8

budgie-cam

Send a text message -> receive a picture of your beautiful bird!
Python
7
star
9

pycon-2018-proposal

[ACCEPTED] My proposal for PyCon 2018
6
star
10

zw-stego

Zero-width steganography implemented in both Python and Javascript
HTML
4
star
11

insightly-mailchimp

Sync contacts by Insight.ly tags and MailChimp groups - with greater flexibility than their builtin integration offers.
PHP
3
star
12

talks

Talks I've given and would love to give!
2
star
13

museums

Search over 6000 museums from across the US
Python
2
star
14

LED_board

Connect an Arduino to an LED Board!
Arduino
2
star
15

digital-resolution

Send a text message -> see your digital resolution up on the screen.
Python
2
star
16

seriously

These 500 schools reported zero sexual assaults on campus over a three-year period.
HTML
1
star
17

bingo-sheets

Generates bingo sheets given a list of items. One of my first Python programs.
Python
1
star
18

format_date

Python function to standardize a given date into the desired_format
Python
1
star
19

git-tests

Throwaway repo to test and better understand reverts, etc
1
star
20

shannonvturner.com

My personal portfolio site
HTML
1
star
21

aclearnight.com

See the stars without light pollution -- let's go stargazing!
HTML
1
star
22

survivor-resources

Resources for survivors of sexual assault
1
star