Skip to content

Instantly share code, notes, and snippets.

@mp4096
Created April 5, 2017 11:57
Show Gist options
  • Save mp4096/04145475ae2b32cc795f08c268d61824 to your computer and use it in GitHub Desktop.
Save mp4096/04145475ae2b32cc795f08c268d61824 to your computer and use it in GitHub Desktop.
An extemely short introduction to Python

An extemely short introduction to Python

  • General information
    • High-level scripting language
    • Dynamic and strong typing
    • Implemented in C (as is NumPy/SciPy)
    • Extremely widespread: Google (YouTube, Google Brain, DeepMind), Dropbox, Microsoft, Intel are the largest supporters
    • Clear, simple syntax
    • Mostly object-oriented, but has a lot of functional influence
    • Named after Monty Python, not the animal!
    • First released in 1991
    • Often compared with Ruby or Perl; in contrast to Ruby...
    • Works on different platforms: Windows, Linux, mac OS, x86, ARM, microcontrollers, ...
  • Applications
    • Literally everything and everywhere
  • Tooling:
    • python (useful: the -i flag)
    • ipython (useful: who and whos, ?)
    • Jupyter Notebook
    • PyCharm (also Community Edition)
    • Spyder
    • pip and conda
  • Python 3 vs Python 2:
    • UTF-8 as default source file encoding
    • Syntax: print function
    • Semantics: Laziness, integer division
    • Unicode strings by default + separate bytes and bytearray classes
    • python vs python3 on Linux
  • Libraries:
    • NumPy
    • SciPy
    • SymPy
    • matplotlib
    • python-control
    • scikit-learn, scikit-image, astropy, ...
    • Keras, TensorFlow, Theano
    • Numba
  • Finding information:
    • Be careful about the docs version (e.g. use the latest NumPy/SciPy docs, Python 3.6 etc.)
    • Use Zeal or Dash
    • Use StackOverflow (just google in English)
    • There always is a solution for your problem!
    • Read docstrings / use help() or ?
    • NumPy/SciPy: If in doubt, read the source
  • Best practices:
    • Zen of Python (PEP 20)
    • PEP 8
    • Hard tabs vs spaces: Use 4 spaces, full stop
    • Flat source code: Use list/set/dict comprehensions and generators
  • Python basics
    • Syntax:
      • definition of variables and functions, default, named and positional args
      • import statements
      • indexing and slicing
      • branches
      • loops
      • IO (print)
      • strings and string interpolation
    • Operators and statements:
      • not
      • @
      • **
      • _ when unpacking
      • None as a nil value
      • pass
    • Data structures:
      • tuples, tuples unpacking
      • lists
      • dicts
      • sets
      • ndarrays
    • Misc:
      • list comprehensions
      • iteration, enumerate, zip
      • functions are first-order citizens
      • laziness: e.g. map, list
    • Naming conventions
      • snake_case and SCREAMING_SNAKE_CASE
      • Underscores magic _
    • Special symbols:
      • __version__
      • __init__()
      • __name__
    • Classes and objects: a completely different story
    • Pitfalls:
      • mutable objects as default args
      • closures capture references (late binding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment