UTOSC 2010/Python Full Meal Deal

From Omnia
Jump to navigation Jump to search

UTOSC

Python at UTOSC [panela.blog-city.com] - http://panela.blog-city.com/python_at_utosc.htm

Python Full Meal Deal

Part I:

Presenter: Matt Harrison

http://panela.blog-city.com

http://files.blog-city.com/files/F05/96843/b/fullmeal.tar.gz

wget http://files.blog-city.com/files/F05/96843/b/fullmeal.tar.gz
tar -zvxf fullmeal.tar.gz

hello.py:

print "hello world"

run:

python hello.py

shebang:

#!/usr/bin/python

Everything is an object:

  • identity (id)
  • type (type)
  • value (mutable or immutable)


  • Mutable: Dictionary, List
  • Immutable: String, Integer, Tuple


Conversion:

  • int()
  • str()
  • float()


Naming convention: PEP8 - Python Enhancement Proposal 8


dir(object) will list all methods one can call on that object

dunder (double under) methods determine what happens when + (__add__) or / (__div__) is called

help("a string".startswith)

comments follow a #


  • Tuples - hetergenenous state (name, age, address)
  • List - homogenous, mutable (list of names)


Whitespace: instead of { use a : and indent consistently (4 spaces)


Functions have docstrings. Accessible via .__doc__

 help(fname)


Part II:

Presenter: Matt Harrison

his slides are excellent!

keywords