python introduction

65
Introduction to Python A readable, dynamic, pleasant, flexible, fast and powerful language

Upload: sofian-hadiwijaya

Post on 15-Aug-2015

96 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Python Introduction

Introduction to Python

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

Page 2: Python Introduction

Overview

•Background

•Syntax

•Types / Operators / Control Flow

•Functions

•Classes

•Tools

Page 3: Python Introduction

What is Python

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

•Object Oriented

•Interpreted

•Strongly typed and Dynamically typed

•Focus on readability and productivity

Page 4: Python Introduction

Features

•Batteries Included

•Everything is an Object

•Interactive Shell

•Strong Introspection

•Cross Platform

•CPython, Jython, IronPython, PyPy

Page 5: Python Introduction

Who Uses Python

•Google

•Youtube

•Spotify

•Nasa

•Etc

Page 6: Python Introduction

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: Python Introduction

Syntax

Page 8: Python Introduction

Hello World

hello_world.py

Page 9: Python Introduction

Indentation

•Most languages don’t care about indentation

•Most humans do

•We tend to group similar things together

Page 10: Python Introduction

Indentation

The else here actually belongs to the 2nd if statement

Page 11: Python Introduction

Indentation

The else here actually belongs to the 2nd if statement

Page 12: Python Introduction

Indentation

I knew a coder like this

Page 13: Python Introduction

Indentation

You should always be explicit

Page 14: Python Introduction

Indentation

Text

Python embraces indentation

Page 15: Python Introduction

Comments

Page 16: Python Introduction

Types

Page 17: Python Introduction

Strings

Page 18: Python Introduction

Numbers

Page 19: Python Introduction

Null

Page 20: Python Introduction

Lists

Page 21: Python Introduction

Lists

Page 22: Python Introduction

Tuple•Tuple just like List

•But immutable

•Assignment using ( )

Page 23: Python Introduction

Dictionaries

Page 24: Python Introduction

Dictionary Methods

Page 25: Python Introduction

Booleans

Page 26: Python Introduction

Operators

Page 27: Python Introduction

Arithmetic

Page 28: Python Introduction

String Manipulation

Page 29: Python Introduction

Logical Comparison

Page 30: Python Introduction

Identity Comparison

Page 31: Python Introduction

Arithmetic Comparison

Page 32: Python Introduction

Control Flow

Page 33: Python Introduction

Conditionals

Page 34: Python Introduction

For Loop

Page 35: Python Introduction

Expanded For Loop

Page 36: Python Introduction

While Loop

Page 37: Python Introduction

List Comprehensions

•Useful for replacing simple for-loops.

Page 38: Python Introduction

Functions

Page 39: Python Introduction

Basic Function

Page 40: Python Introduction

Function Arguments

Page 41: Python Introduction

Arbitrary Arguments

Page 42: Python Introduction

Fibonacci

Page 43: Python Introduction

Fibonacci Generator

Page 44: Python Introduction

Classes

Page 45: Python Introduction

Class Declaration

Page 46: Python Introduction

Class Attributes

•Attributes assigned at class declaration should always be immutable

Page 47: Python Introduction

Class Methods

Page 48: Python Introduction

Class Instantiation & Attribute Access

Page 49: Python Introduction

Class Inheritance

Page 50: Python Introduction

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 51: Python Introduction

Imports

•Allows code isolation and re-use

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

Page 52: Python Introduction

Imports

Page 53: Python Introduction

More Imports

Page 54: Python Introduction

Error Handling

Page 55: Python Introduction

Documentation

Page 56: Python Introduction

Docstrings

Page 57: Python Introduction

Tools

Page 58: Python Introduction

Web Frameworks

•Django

•Flask

•Pylons

•TurboGears

•Zope

•Grok

Page 59: Python Introduction

IDEs

•Emacs

•Vim

•Komodo

•PyCharm

•Eclipse (PyDev)

Page 60: Python Introduction

Package Management

Page 61: Python Introduction

Resources

•http://python.org/

•http://diveintopython.org/

•http://djangoproject.com/

Page 62: Python Introduction

Example

Page 63: Python Introduction

Going Further

•Decorators

•Context Managers

•Lambda functions

•Generators

•...

Page 64: Python Introduction

Questions?

Page 65: Python Introduction

Thanks!