Download presentation
Presentation is loading. Please wait.
Published byAva Murray Modified over 11 years ago
1
Python www.python.org
2
Whats in a name? Snake logos and mascot notwithstanding, its named after Monty Pythons Flying Circus Humor-impaired can safely ignore the spam references :-) Nobody expects the Spanish inquisition
3
What is Python? O-O rapid prototyping language Not just a scripting language Not just another Perl-wannabe Extensible (add new modules) –C/C++/Fortran/whatever –Java (through JPython) Embeddable in applications
4
Touchy-feely properties Free (open source) –copyrighted but use not restricted Mature (9 years old) Supportive user community –& more books in the pipeline! Elegant design, easy to learn –reads like pseudo-code –Suitable as first language
5
High-level properties Extremely portable –Unix, Windows, Mac, BeOS, Win/CE, DOS, OS/2, Amiga, VMS, Cray, … Compiles to interpreted byte code –compilation is implicit and automatic Memory mgt through ref counting –easier for C/C++ extensions Safe: no core dumps
6
Interfaces to... COM, DCOM, ODBC Commercial databases Java (JPython) Many GUI libraries –platform-independent Tk, wxWindows, GTK –platform-specific MFC, MacOS, X11
7
Language properties Everything is an object Modules, classes, functions Exception handling Dynamic typing, polymorphism Static scoping Operator overloading Indentation for block structure –Otherwise conventional syntax
8
High-level data types Numbers: int, long, float, complex Strings: immutable Lists and dictionaries: containers Other types for e.g. binary data, regular expressions, introspection Extension modules can define new built-in data types
9
What is it used for? rapid prototyping web scripting throw-away, ad hoc programming steering scientific applications extension language XML processing database applications GUI applications
10
Who is using it? LLNL, Fermilab (steering) Alice project at CMU (3D graphics) ObjectDomain (extend UML tool) Infoseek (ext. language, scripting) Industrial Light & Magic (everything) Yahoo! (CGI in Yahoo!mail) Digital Creations (Zope website mgt) RedHat (Linux installation tools)
11
Compared to Perl Easier to learn –especially for infrequent users More readable code –improved code maintenance Fewer magical side effects More safety guarantees Better Java integration Some things slower
12
Compared to Java Code 5-10 times more concise Dynamic typing Much quicker development –no compilation phase –less typing Yes, it runs slower –but development is much faster! Ditto (but more so) for C/C++
13
Compared to Tcl Real datatypes, object-orientation More differentiated syntax Much faster (even than Tcl 8.0) Can use threads Less need for C extensions –hence fewer extension conflicts Better Java integration Python uses Tk as de-facto GUI std
14
JPython Seamless integration with Java Separate implementation –classic Python called CPython here Implements the same language Different set of standard modules differences in gray areas –e.g. some different introspection calls –different command line options, etc.
15
Java integration Interactive Compiles direct to Java bytecode Import Java classes directly Subclass Java classes –pass instances back to Java Java beans integration Can compile into Java class files –run as applet in browsers
16
Example function def gcd(a, b): greatest common divisor while a != 0: a, b = b%a, a # parallel assignment return b
17
Example class class Stack: A well-known data structure… # doc string def __init__(self): # constructor self.items = [] def push(self, x): self.items.append(x) # the sky is the limit def pop(self): x = self.items[-1] # what happens if its empty? del self.items[-1] return x def empty(self): return len(self.items) == 0
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.