+ All Categories
Home > Software > Introduction to Python-2

Introduction to Python-2

Date post: 28-Jul-2015
Category:
Upload: shuai-liu
View: 168 times
Download: 1 times
Share this document with a friend
Popular Tags:
34
Intro to Python by Shuai Liu
Transcript

Intro to Pythonby Shuai Liu

agenda

• History & Basics

• Advanced & Be Pythonic

• Awesome Python Frameworks

Advanced & Be Pythonic

Review

• int & float & bool

• string & list & tuple

• dict

• loop & branch

• def methods

Something interesting…

def foo(a, b): """My niubility methods.""" return a + b

"""My niubility methods."""

>>> print foo.__doc__ >>> My niubility methods.

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

Pythonic

–Martijn Faassen, founder of the lxml (XML library for Python)

“Pythonic is to use the Python constructs and datastructures with clean,

readable idioms.”

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

value exchange

temp = foo foo = bar bar = temp

foo, bar = bar, foo

string concatenating

s = “hello” + “world”

s = “”.join([“hello”, “world”])

λ

lambda

def foo(x): return x ** 2

lambda x : x ** 2

>>> a = lambda x : x ** 2 >>> a(5) >>> 25

filter & map & reduce

>>> filter(function, iterable)

>>> map(function, iterable)

>>> reduce(function, iterable)

filter

map

reduce

List comprehensions

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

two more things…

PEP

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

pip

pip

• A tool for installing and managing Python packages.

• $ sudo pip install Requests

Resources

IDE

‘+’.join([ , ])

IDE

Summary

• OO

• lambda & three functions

• list comprehensions

• resources

Thanks


Recommended