Python
Upcoming SlideShare
Loading in...5
×
 

Python

on

  • 3,496 views

Python's history, philosophy. Lists, dicts, tuples. OOP in python, inheritance, data abstraction, polymorphism.

Python's history, philosophy. Lists, dicts, tuples. OOP in python, inheritance, data abstraction, polymorphism.

Statistics

Views

Total Views
3,496
Views on SlideShare
3,490
Embed Views
6

Actions

Likes
6
Downloads
225
Comments
0

2 Embeds 6

http://localhost 4
http://www.slideshare.net 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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

Python Python Presentation Transcript

  • PYTHON Volkan Tüfekçi – Gülcan Aydın 26.12.2007
  • History Philosphy Usage
    • Guido van Rossum 1989 Hobby Language
    • ABC – Modula 3 – Unix/C – Common Lisp - Haskell
    • Dislikes:
      • D ifficulty of adding new "primitive" operations
      • M onolithic, "closed system“ , basic I/O operations
      • I deosyncratic syntax (all uppercase keywords!)
    • Aims:
      • Readability
      • Rely on the Unix infrastructure and conventions, without being Unix-bound
      • I mportance of programmer effort over computer effort
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • History Philosphy Usage(cont.)
    • 1991
    • S yntax and semantics are minimalist , while the standard library is large and comprehensive
    • multi-paradigm programming language :
      • object orientation and structured programming -> fully
      • functional programming and aspect-oriented programming -> by language features
    • pyDBC and Contracts for Python which allow Design by Contract
    • dynamic name resolution (late binding)
    • New built-in modules are easily written in C or C++
    • Python philosophy rejects exuberant syntax, such as in Perl
    • PyQt, PyGTK, PyCon, PyPy
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • History Philosphy Usage(cont.)
    • Nasa, Google, YouTube, BitTorrent, Air Canada’s Reservation Management
    • TurboGears, Django(NewYork Times’ web site)
    • Maya, Blender
    • Fedora, Gentoo, Pardus
    • Jython, IronPython
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Introduction to O-O Python
    • Python is an object-oriented programming language.
    • Supports procedural programming with modules and functions.
    • Generally, the O-O paradigm is suitable when you want to group state (data) and behavior (code) together in handy packets of functionality.
    • The procedural paradigm, based on modules and functions, tends to be simpler and is more suitable when you don't need any of the benefits of object-oriented programming.
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Syntax
    • All values in Python can be used as logic values. Some of the more “empty” ones, like [], 0, “” and None represent logical falsity, while most other values (like [0], 1 or “Hello, world”) represent logical truth.
    • if 0 < month <= 12:
    • doSomething()
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Dictionaries 1 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
    • A dictionary in Python is like an instance of the Hashtable class in Java
    • No duplicate member
    • No order
    • Mutable
  • Dictionaries 2 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • List s 1 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • List s 2 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • List s 3 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • List & Dictionary Examples
    • L=[1,2,3,4,5]
      • IMPORTANT : The value will be stored into a range of memory blocks, and what if we do this?
    • L2=L
      • It make L2 refers to the same memory blocks where L points to. Example;
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • List C omprehension s 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Tuples 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
    • A tuple is an immutable list. A tuple can not be changed in any way once it is created
    • Tuples are faster than lists
    • It makes your code safer if you “write-protect” data
    • Tuples can be converted into lists, and vice-versa.
  • Assigning Variables 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • String Formatting & Concatenating 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN # 1 membered Tuple!!! # Strong typed
  • Importing Modules & Getting Help 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • String Operation Examples 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Modules
    • from UserDict import UserDict
  • Constructor
    • A constructor is a method that initializes a newly created object.
    • The overridden derived-class constructor usually calls the base-class constructor, to initialize base-class attributes before initializing derived-class attributes.
    • If a derived class does not define a constructor, the class’s base-class constructor executes when the client creates a new object of the class.
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Destructor & Static Variable 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN D oes not actually destroy the object # Static variable # 0 # 2 # 0
  • Static Methods 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Property Descriptor 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Slots Attribute 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN >>>8
  • Inheritance
    • Inheritance is a form of software reusability in which new classes are created from existing classes by absorbing their attributes and behaviors.
      • The new class is referred to as a derived class, inherit from the class referred to as base class.
      • With single inheritance, a class is derived from one base class.
      • With multiple inheritance, a derived class inherits from several base classes.
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • (cont.)
    • We distinguish between “is-a” relationships and “has-a” relationships:
      • “ Is a” is inheritance. In an “is a” relationship, an object of a derived-class type may also be treated as an object of the base-class type.
      • “ Has a” is composition. In a “has a” relationship, an object has references to one or more objects of other classes as members.
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • “ is a”
    • Inheritance hierarchy for university community members :
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Multiple Inheritance and Name Clash Problem
    • class Base1:
      • def amethod(self):
      • print &quot;Base1“
      • class Base2(Base1): pass # pass!!!
      • class Base3:
      • def amethod(self):
      • print &quot;Base3&quot;
      • class Derived(Base2, Base3): pass
      • aninstance = Derived( )
      • aninstance.amethod( ) # prints: &quot;Base1&quot;
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Data Abstraction
    • One of the fundamental principles of good software engineering is that a client should not need to know how a class is implemented to use that class.
    • Python’s use of modules facilitates this data abstraction—a program can import a class definition and use the class without knowing how the class is implemented.
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Encapsulation
    • No methods or member variables are protected (or private or the like) in Python.
    • Encapsulation is pretty much a matter of programming style.
      • If you really need it, there are naming-conventions that will allow some privacy.
        • such as; _ _ident
        • Python compiler implicitly changes the identifier into _classname_ _ident , where classname is the name of the class.
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Example of Private Data Access 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Abstract Classes 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN Traceback (most recent call last): b.earnings() raise NotImplementedError, &quot;Cannot call abstract method&quot; NotImplementedError: Cannot call abstract method
  • Polymorphism 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Polymorphism 2 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Polymorphism 3 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Polymorphism 4 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Polymorphism 5 29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • Composition vs. Inheritance
    • composition of existing classes
    • Employee is a BirthDate or that an Employee is a TelephoneNumber
    • Employee has a BirthDate and that an Employee
    • has a TelephoneNumber.
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN
  • “ Uses A” and “Knows A” Relationships
    • a person object is not a car and a person object does not contain a car, a person object certainly uses a car
    • A program uses an object simply by calling a method of that object through a reference.
    • one object is said to have a knows a relationship with the other object; this is sometimes called an association.
    29/05/09 CSE 494 Volkan TÜFEKÇİ - Gülcan AYDIN