python-get-started icon indicating copy to clipboard operation
python-get-started copied to clipboard

Snippets to jump start learning Python

python-get-started

A collection of basic Python examples designed to get a student up and running on the language.

More tutorials and documentation:

  • The official Python docs: https://www.python.org/doc/

  • LearnPython.org: http://www.learnpython.org/

After you've mastered these examples, also check out:

  • More Python snippets I find handy: https://github.com/anthonydb/python-snippets

  • Catch the Cat: A text-based game (introduces objects and advanced coding): https://github.com/anthonydb/catch-the-cat

  • Tom Meagher's repo for the 2014 NICAR Python mini-bootcamp: https://github.com/tommeagher/pycar14

Outline

1-variables-data-structures.py

  • Integers

  • Decimals

  • Strings

  • Lists

  • Tuples

  • Dictionaries

2-string-methods.py

  • Slicing

  • Mods

3-control-structures.py

  • if ... then ... else

  • while

  • for

4-file-io.py

  • Opening, reading from and writing to files

  • Bonus: Word frequency counter

5-web-scraping.py

  • Using Requests and BeautifulSoup to fetch and parse a web page

6-regular-expressions.py

  • Parsing text with regular expessions

6.1-regular-expressions-web-scrape.py

  • Applying regular expressions to scraping nuclear reactor data

7-functions.py

  • Creating functions

8-csvkit.txt

  • Using the csvkit Python library to handle CSV files