Slide 1

Slide 1 text

Intro to Python by Shuai Liu

Slide 2

Slide 2 text

agenda • History & Basics • Advanced & Be Pythonic • Awesome Python Frameworks

Slide 3

Slide 3 text

Advanced & Be Pythonic

Slide 4

Slide 4 text

Review • int & float & bool • string & list & tuple • dict • loop & branch • def methods

Slide 5

Slide 5 text

Something interesting…

Slide 6

Slide 6 text

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

Slide 15

Slide 15 text

filter & map & reduce

Slide 16

Slide 16 text

>>> filter(function, iterable) >>> map(function, iterable) >>> reduce(function, iterable)

Slide 17

Slide 17 text

filter

Slide 18

Slide 18 text

map

Slide 19

Slide 19 text

reduce

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

List comprehensions

Slide 22

Slide 22 text

>>> 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

Slide 34

Slide 34 text

Thanks