Introduction to Python
Upcoming SlideShare
Loading in...5
×
 

Introduction to Python

on

  • 510 views

 

Statistics

Views

Total Views
510
Views on SlideShare
510
Embed Views
0

Actions

Likes
0
Downloads
20
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Introduction to Python Introduction to Python Presentation Transcript

    • Python's Birth
    • Xmas 1989
    • About two weeks of time off with no plans
    • Had it all in my head
    • Fat Mac with Lightspeed C on 20 MB hard drive
    • First code: a parser generator
    • Soon followed: a running program!
  • TIOBE Programming Community Index for March 2011 Position Mar 2011 Position Mar 2010 Programming Language Ratings Mar 2011 Delta Mar 2010 1 1 Java 19.711% +2.20% 2 2 C 15.262% -2.02% 3 4 C++ 8.754% -0.86% 4 6 C# 7.210% +2.95% 5 3 PHP 6.566% -3.34% 6 7 Python 5.737% +1.51% 7 5 (Visual) Basic 4.710% -1.86% 8 12 Objective-C 3.518% +1.55% 9 8 Perl 1.969% -1.85% 10 10 JavaScript 1.866% -0.78%
    • What is Python?
    • O-O rapid prototyping language
    • Not just a scripting language
    • Not just another Perl
    • Easy to learn, read, use
    • Extensible (add new modules)
      • C/C++/Fortran/whatever
      • Java (through Jython)
    • Embeddable in applications
    • What is it used for?
    • rapid prototyping
    • web programming (client and server side)
    • ad hoc programming ("scripting")
    • steering scientific applications
    • extension language
    • XML processing
    • database applications
    • GUI applications
    • education
    • Who is using it?
    • Google (various projects)
    • NASA (several projects)
    • NYSE (one of only three languages "on the floor")
    • Industrial Light & Magic (everything)
    • Yahoo! (Yahoo mail & groups)
    • RealNetworks (function and load testing)
    • RedHat (Linux installation tools)
    • LLNL, Fermilab (steering scientific applications)
    • Zope Corporation (content management)
    • ObjectDomain (embedded Jython in UML tool)
    • Alice project at CMU (accessible 3D graphics)
    • More success stories at www.pythonology.com
    • Language properties
    • Everything is an object
    • Packages, modules, classes, functions
    • Exception handling
    • Dynamic typing, polymorphism
    • Static scoping
    • Operator overloading
    • Indentation for block structure
      • Otherwise conventional syntax
    • Compared to Perl
    • Easier to learn
      • very important for infrequent users
    • More readable code
    • More maintainable code
    • Fewer “magical” side effects
    • More “safety” guarantees
    • Better Java integration
    • The Zen of Python
    • Beautiful is better than ugly.
    • Explicit is better than implicit.
    • Simple is better than complex.
    • Complex is better than complicated.
    • Flat is better than nested.
    • Sparse is better than dense.
    • Readability counts.
    • Special cases aren't special enough to break the rules.
    • Although practicality beats purity.
    • Errors should never pass silently.
    • Unless explicitly silenced.
    • In the face of ambiguity, refuse the temptation to guess.
    • There should be one— and preferably only one —obvious way to do it.
    • Although that way may not be obvious at first unless you're Dutch.
    • Now is better than never.
    • Although never is often better than right now.
    • If the implementation is hard to explain, it's a bad idea.
    • If the implementation is easy to explain, it may be a good idea.
    • Namespaces are one honking great idea — let's do more of those!
      (a poem by Tim Peters)
  • Getting help
    • http://python.org/
    • >>> help()
  • Indentation def foo(x): if x is not None and x == 0: bar() baz() else: qux(x) foo(x - 1)
  • Type hierarchy
    • None, NotImplemented, Ellipsis
    • numbers.Number
      • numbers.Integral
        • Plain integers: -2147483648 ... 2147483647
        • Long integers
        • Booleans
      • numbers.Real (float): double precision
      • numbers.Complex
  • Type hierarchy
    • Sequences
      • Immutable sequences
        • Strings: “asdf”
        • Unicode: u”unicode asdf”
        • Tuples: 1, 2, 3 1, ()
      • Mutable sequences
        • Lists: [1, 2, 3]
        • Byte Arrays: bytearray()
  • Type hierarchy
    • Set types
      • Sets: set()
      • Frozen sets: frozenset()
    • Mappings
      • Dictionaries: {'a': 1, 'b': 2}
  • Type hierarchy
    • Callable types
      • User-defined functions
      • User-defined methods
      • Generator functions
      • Built-in functions
      • Built-in methods
      • Class Types
      • Classic Classes
      • Class instances
  • Type hierarchy
    • Classes
    • Class instances
    • Files
    • Internal types
      • Code objects
      • Frame objects
      • Traceback objects
      • Slice objects
      • Static method objects
      • Class method objects
  • Control flow
    • The if statement
    • if expression1 :
    • elif expression2 :
    • else:
  • Control flow
    • The while statement
    • while expression :
    • else:
  • Control flow
    • The for statement
    • for target_list in expression_list :
    • else:
  • Function definitions
      def funcname ( param1, param2, param3=value, param4=value ):
      funcname(1, 2) funcname(1, 2, 3, 4) funcname(1, 2, param4=4, param3=3) funcname(param4=1, param3=2, param2=3, param1=4)
    • Example function
      def gcd(a, b): "greatest common divisor" while a != 0: a, b = b%a, a # parallel assignment return b
  • Modules
    • import re
    • from sys import stdout, stderr
    • from os import system as hack_them_all
  • Modules
    • sys
    • os
    • re
    • struct
    • os.path
    • pickle, cPickle, shelve
    • socket, select, threading