Programming in Python Jarkko Toivonen Department of Computer Science University of Helsinki September 18, 2009 Administration Organisation Contents of the Course Overview of Python Jarkko Toivonen (CS Department) Programming in Python 1 / 18 Jarkko Toivonen (CS Department) Programming in Python 2 / 18 Organisation Contents of the Course Basic information Teaching Organisation Contents of the Course Voluntary intermediate level course Teaching language: English Fall 2009, Period I, 4 credit units Registering for the course through ilmo: https://ilmo.cs.helsinki.fi/ Course home page: http://www.cs.helsinki.fi/u/jttoivon/python-09/ Lectures: Tuesday 12-14, Thursday 10-12 in Auditorium B123 Exception: 24th of September at 8-10 in Auditorium B123??? Exercises: two hours per week starts already in the first week See homepage or ilmo for times and places Course exam: Wednesday 21th of October at 9-12 in B123 Verify the time and place few days before the exam from here http://www.cs.helsinki.fi/kokeet/kkokeets09.html Jarkko Toivonen (CS Department) Programming in Python 3 / 18 Jarkko Toivonen (CS Department) Programming in Python 4 / 18
Evaluation Organisation Contents of the Course Organisation Contents of the Course Prerequisites and Aims Exam 20p + Exercises 20p + Project 20p = 60p Roughly: 30 points to get lowest grade (1/5) and 50 points for grade 5/5 The course cannot be passed by a separate exam Prerequisites: programming skill in at least one language, and basic computer skills (Linux) Aims: Can write portable applications in Python that work under various platforms, like Windows, Linux, Mac,... Knows the strengths and weaknesses of Python, and can therefore choose when to use Python and when use some other tool or language. Learns good software engineerings habits of writing clear code and documentation, and testing for correctness. Jarkko Toivonen (CS Department) Programming in Python 5 / 18 Jarkko Toivonen (CS Department) Programming in Python 6 / 18 Literature Organisation Contents of the Course Course book: Alex Martelli, Python in a Nutshell, O Reilly 2006 For additional books, and links to online resources, see the course homepage. Jarkko Toivonen (CS Department) Programming in Python 7 / 18 Organisation Contents of the Course Tentative list of topics of the course Basic concepts of Python Data types and variables Expressions Flow control and functions Basic input and output Data structures: lists, tuples, sets, dictionaries Objects and classes Exceptions Modules String handling Regular expressions File processing Documentation and testing Overview of NumPy and TkInter GUI libraries (if time permits) Jarkko Toivonen (CS Department) Programming in Python 8 / 18
History of Python Who are using Python? Developer Guido van Rossum Development started in the end of 80 s First release in 1991 Descendant of ABC language Other influencees: C, LISP, Haskell, Modula-3, Perl, Java,... Nowadays Python is developed by large group of programmers Open Source development model Many companies rely on Python: YouTube, Google, Industrial Light & Magic,... Jarkko Toivonen (CS Department) Programming in Python 9 / 18 Jarkko Toivonen (CS Department) Programming in Python 10 / 18 Where does it work? Facilities at our department On several operating systems, such as Windows, Unix, Mac Also different implementations: The main implementation is written in C, and is referred to as CPython Jython is implemented in Java IronPython implemented in the.net environment Each of these implementations allow extending Python with the implementation language Main platform: CPython on Linux Both version 2.5 and 3.0 are installed The computer system is in the state of change Things are guaranteed to work at least on machines melkki.cs.helsinki.fi and melkinpaasi.cs.helsinki.fi Windows and Mac are not supported, but you can use them on your own. Jarkko Toivonen (CS Department) Programming in Python 11 / 18 Jarkko Toivonen (CS Department) Programming in Python 12 / 18
More information Which Python version to use? Python homepage http://www.python.org Documentation http://www.python.org/doc/ Python has also an internal documentation system On this course we will concentrate on version 2.5 We will also look at some of the bigger new features of Python 3 Python version 3.0 breaks the downward compatibility Not really any books on version 3 yet Not many external libraries (like numpy) support version 3, yet There s lot of existing code written in Python 2.5, and still continues to be written Both versions are installed on our departments machines A conversion program 2to3 exists as well Jarkko Toivonen (CS Department) Programming in Python 13 / 18 Jarkko Toivonen (CS Department) Programming in Python 14 / 18 What kind of language Python is? Features Interactive Strongly typed Dynamic typing Duck typing Compiled and interpreted: Source code (.py extension) compiled into byte code Byte code (.pyc extension) is run with a virtual machine.py.pyc compiler Consistent and simple language: this makes it easy to learn Very High Level Language good set of data structures rich standard library Allows fast developing and prototyping May sometimes be a bit slow, due to it being dynamic and interpreted... but computers are cheap and programmer come expensive Python has classes, modules, and other modern features... but doesn t force you to use them virtual machine Jarkko Toivonen (CS Department) Programming in Python 15 / 18 Jarkko Toivonen (CS Department) Programming in Python 16 / 18
Hello world in Java and Python Why do we do programs? Java version: public class hello { public static void main(string[] args) { System.out.println("Hello, World!"); } } Python version: print "Hello, World!" To automate boring, repetitive and error prone tasks To compute and process data To store vast amounts of data To visualise and auralise data A program is a set of instructions that tell the computer what to do. Jarkko Toivonen (CS Department) Programming in Python 17 / 18 Jarkko Toivonen (CS Department) Programming in Python 18 / 18