64
Introduction to Python A readable, dynamic, pleasant, flexible, fast and powerful language Nowell Strite Manager of Tech Solutions @ PBS [email protected]

Introduction to Python

Embed Size (px)

DESCRIPTION

Introduction to Python slides from the Vermont Code Camp 2010 gathering.

Citation preview

Page 1: Introduction to Python

Introduction to Python

A readable, dynamic, pleasant, flexible, fast and powerful language

Nowell Strite Manager of Tech Solutions @ PBS

[email protected]

Page 2: Introduction to Python

Overview

•Background

•Syntax

•Types / Operators / Control Flow

•Functions

•Classes

•Tools

Page 3: Introduction to Python

What is Python

•Multi-purpose (Web, GUI, Scripting, etc.)

•Object Oriented

•Interpreted

•Strongly typed and Dynamically typed

•Focus on readability and productivity

Page 4: Introduction to Python

Features

•Batteries Included

•Everything is an Object

•Interactive Shell

•Strong Introspection

•Cross Platform

•CPython, Jython, IronPython, PyPy

Page 5: Introduction to Python

Who Uses Python

•Google

•PBS

•NASA

•Library of Congress

•the ONION

•...the list goes on...

Page 6: Introduction to Python

Releases•Created in 1989 by Guido Van Rossum

•Python 1.0 released in 1994

•Python 2.0 released in 2000

•Python 3.0 released in 2008

•Python 2.7 is the recommended version

•3.0 adoption will take a few years

Page 7: Introduction to Python

Syntax

Page 8: Introduction to Python

Hello World

hello_world.py

Page 9: Introduction to Python

Indentation

•Most languages don’t care about indentation

•Most humans do

•We tend to group similar things together

Page 10: Introduction to Python

Indentation

The else here actually belongs to the 2nd if statement

Page 11: Introduction to Python

Indentation

The else here actually belongs to the 2nd if statement

Page 12: Introduction to Python

Indentation

I knew a coder like this

Page 13: Introduction to Python

Indentation

You should always be explicit

Page 14: Introduction to Python

Indentation

Text

Python embraces indentation

Page 15: Introduction to Python

Comments

Page 16: Introduction to Python

Types

Page 17: Introduction to Python

Strings

Page 18: Introduction to Python

Numbers

Page 19: Introduction to Python

Null

Page 20: Introduction to Python

Lists

Page 21: Introduction to Python

Lists

Page 22: Introduction to Python

Dictionaries

Page 23: Introduction to Python

Dictionary Methods

Page 24: Introduction to Python

Booleans

Page 25: Introduction to Python

Operators

Page 26: Introduction to Python

Arithmetic

Page 27: Introduction to Python

String Manipulation

Page 28: Introduction to Python

Logical Comparison

Page 29: Introduction to Python

Identity Comparison

Page 30: Introduction to Python

Arithmetic Comparison

Page 31: Introduction to Python

Control Flow

Page 32: Introduction to Python

Conditionals

Page 33: Introduction to Python

For Loop

Page 34: Introduction to Python

Expanded For Loop

Page 35: Introduction to Python

While Loop

Page 36: Introduction to Python

List Comprehensions

•Useful for replacing simple for-loops.

Page 37: Introduction to Python

Functions

Page 38: Introduction to Python

Basic Function

Page 39: Introduction to Python

Function Arguments

Page 40: Introduction to Python

Arbitrary Arguments

Page 41: Introduction to Python

Fibonacci

Page 42: Introduction to Python

Fibonacci Generator

Page 43: Introduction to Python

Classes

Page 44: Introduction to Python

Class Declaration

Page 45: Introduction to Python

Class Attributes

•Attributes assigned at class declaration should always be immutable

Page 46: Introduction to Python

Class Methods

Page 47: Introduction to Python

Class Instantiation & Attribute Access

Page 48: Introduction to Python

Class Inheritance

Page 49: Introduction to Python

Python’s Way

•No interfaces

•No real private attributes/functions

•Private attributes start (but do not end) with double underscores.

•Special class methods start and end with double underscores.

•__init__, __doc__, __cmp__, __str__

Page 50: Introduction to Python

Imports

•Allows code isolation and re-use

•Adds references to variables/classes/functions/etc. into current namespace

Page 51: Introduction to Python

Imports

Page 52: Introduction to Python

More Imports

Page 53: Introduction to Python

Error Handling

Page 54: Introduction to Python

Documentation

Page 55: Introduction to Python

Docstrings

Page 56: Introduction to Python

Tools

Page 57: Introduction to Python

Web Frameworks

•Django

•Flask

•Pylons

•TurboGears

•Zope

•Grok

Page 58: Introduction to Python

IDEs

•Emacs

•Vim

•Komodo

•PyCharm

•Eclipse (PyDev)

Page 59: Introduction to Python

Package Management

Page 60: Introduction to Python

Resources

•http://python.org/

•http://diveintopython.org/

•http://djangoproject.com/

Page 61: Introduction to Python

Example

Page 62: Introduction to Python

Going Further

•Decorators

•Context Managers

•Lambda functions

•Generators

•...

Page 63: Introduction to Python

Questions?

Page 64: Introduction to Python

Thanks!