ebook img

Python (& Jython) introduction - Benvenuti al sito di Alex Martelli PDF

56 Pages·2003·0.37 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Python (& Jython) introduction - Benvenuti al sito di Alex Martelli

Python ( ) introduction & Jython for C++ and Java programmers Alex Martelli <[email protected]> STRAKT © 2003 AB Strakt April 3, 2003 Python is... ...: lots of nice buzzwords a Very-High-Level Language (VHLL) (cid:132) clean, spare syntax (cid:132) simple, regular, orthogonal semantics (cid:132) high-productivity (cid:132) open-source, cross-platform (cid:132) object-oriented (cid:132) ... (cid:132) STRAKT © 2003 AB Strakt -- A. Martelli April 3, 2003 1 Python is... ...: a lot like Java compiler to bytecode + VM/interpreter (cid:132) • however, compilation is implicit (“auto-make”) everything (in 2.2) inherits from object (cid:132) consistent “object-reference” semantics (cid:132) • assignment, argument-passing, ... • applies to numbers too (immutable, like strings) large, powerful standard library (cid:132) introspection, serialization, threading... (cid:132) STRAKT © 2003 AB Strakt -- A. Martelli April 3, 2003 2 Python is... ...: a lot like C++ multi-paradigm (cid:132) • object-oriented, procedural, ... multiple inheritance (cid:132) operator overloading (cid:132) signature-based polymorphism (cid:132) • as if “everything was a template”... w/ clean syntax choices, choices everywhere (cid:132) • GUIs, Web server frameworks, COM/Corba/... STRAKT © 2003 AB Strakt -- A. Martelli April 3, 2003 3 Python is... ...: quite unlike either strong but dynamic typing (cid:132) • objects have (strong) types, names don’t • no declarations -- only statements clean syntax, minimal “chart-junk” (cid:132) • blocks have no { } -- just indentation • if/while have no ( ) most everything is a first-class object (cid:132) • including classes, functions, modules, packages... STRAKT © 2003 AB Strakt -- A. Martelli April 3, 2003 4 Python versions/releases Classic Python: currently 2.2 -> 2.3 (cid:132) • implemented in 1990-level ISO C Jython: currently 2.1 -> (2.2/2.3) (cid:132) • implemented as 100% pure Java • deploy just like Java, on a JVM • transparently use/extend/implement arbitrary Java classes and interfaces / compile to Java / ... Others: experimental/research level (cid:132) • Python.NET , PyPy , Vyper (O’CAML), ... STRAKT © 2003 AB Strakt -- A. Martelli April 3, 2003 5 Python resources on the net http:// www.python.org (cid:132) • just about everything: downloads, docs, mailing lists, SIGs, pointers to [whatever], ... • http://www.python.org/ftp/python/2.3/Python-2.3a2.exe http://www.jython.org (cid:132) • mostly Jython-specific stuff news:comp.lang.python (cid:132) • any kind of question, request, discussion http://www.google.com ( ) no, really!!! (cid:132) STRAKT © 2003 AB Strakt -- A. Martelli April 3, 2003 6 Python fundamentals interactive interpreter (text and IDLE) (cid:132) • mostly for trying things out, or as a calculator • prompts with >>>, shows expressions' results program files (afile.py, afile.pyc, ...) (cid:132) • for most uses; compilation is automatic assignment ( ): simplest form (cid:132) • name = <any expression> • creates name if needed, binds it to the value • names are not declared, and have no type per se STRAKT © 2003 AB Strakt -- A. Martelli April 3, 2003 7 assignments, print myvar = 'hello' # creates a name myvar = 23 # rebinds name question = answer = 42 myvar, answer = answer, myvar print myvar, answer, question 42, 23, 42 if myvar<20: myvar = 10 # not executed if myvar>40: myvar = 50 # executed print myvar 50 STRAKT © 2003 AB Strakt -- A. Martelli April 3, 2003 8 conditional statements if question>30: # 'if' guards a suite question = 20 # the suite is shown x = 33 # by its indentation else: # optional 'else' x = 99 # indentation again if x<30: myvar = 10 # not met elif x<40: myvar = 20 # met elif x<50: myvar = 40 # not evaluated else: myvar = 40 # this neither print x, question, myvar 33 20 20 STRAKT © 2003 AB Strakt -- A. Martelli April 3, 2003 9

Description:
• the Jython interpreter is accessible from Java. Title: Python for C++ and Java Programmers Author: Alex Martelli Subject: fast-paced Python tutorial Created Date:
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.