def foo(a, b):
"""My niubility methods."""
return a + b
"""My niubility methods."""
>>> print foo.__doc__
>>> My niubility methods.
Slide 7
Slide 7 text
class Person(object):
"""My first class"""
version = 1.0
def __init__(self, name):
self.name = name
print "__init__ called"
def get_name(self):
"""Return the name"""
return self.name
Slide 8
Slide 8 text
Pythonic
Slide 9
Slide 9 text
–Martijn Faassen, founder of the lxml (XML library for Python)
“Pythonic is to use the Python constructs and
datastructures with clean,
readable idioms.”
Slide 10
Slide 10 text
enumerate
l = [0, 1, 2, 3, 4]
for i in range(len(l)):
print i, l[i]
for i, element in enumerate(l):
print i, element
Slide 11
Slide 11 text
value exchange
temp = foo
foo = bar
bar = temp
foo, bar = bar, foo
Slide 12
Slide 12 text
string concatenating
s = “hello” + “world”
s = “”.join([“hello”, “world”])
Slide 13
Slide 13 text
λ
Slide 14
Slide 14 text
lambda
def foo(x):
return x ** 2
lambda x : x ** 2
>>> a = lambda x : x ** 2
>>> a(5)
>>> 25
>>> a = map(lambda x : x ** 2, range(10))
>>> a = [ x ** 2 for x in range(10)]
>>> a = filter(lambda x : x % 2, range(10))
>>> a = [x for x in range(10) if x % 2]
Slide 23
Slide 23 text
No content
Slide 24
Slide 24 text
two more things…
Slide 25
Slide 25 text
PEP
Slide 26
Slide 26 text
Python Enhancement
Proposals
num title owner
1
PEP Purpose and
Guidelines
Warsaw, Hylton, Goodger,
Coghlan
4
Deprecation of Standard
Modules
von Löwis
5
Guidelines for Language
Evolution
Prescod
8
Style Guide for Python
Code
GvR, Warsaw, Coghlan
Slide 27
Slide 27 text
pip
Slide 28
Slide 28 text
pip
• A tool for installing and managing Python packages.
• $ sudo pip install Requests
Slide 29
Slide 29 text
Resources
Slide 30
Slide 30 text
No content
Slide 31
Slide 31 text
IDE
‘+’.join([ , ])
Slide 32
Slide 32 text
IDE
Slide 33
Slide 33 text
Summary
• OO
• lambda & three functions
• list comprehensions
• resources