Introduction to Python Arno Proeme, ARCHER CSE Team [email protected] Attributed in part to Jussi Enkovaara & Martti Louhivuori, CSC Helsinki Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en_US This means you are free to copy and redistribute the material and adapt and build on the material under the following terms: You must give appropriate credit, provide a link to the license and indicate if changes were made. If you adapt or build on the material you must distribute your work under the same license as the original. Note that this presentation contains images owned by others. Please seek their permission before reusing these images. h"p://www.archer.ac.uk [email protected] Python origins • Created early 1990s (Guido van Rossum, CWI) • Driven by desire to provide more programmer-friendly alternative to C to speed up application development • Inspired by an earlier interactive programming environment and language (ABC) • Not created specifically for scientific computing (unlike e.g. Fortran) Python now • Most popular first taught programming language at top 39 US computer science departments • Used by Youtube, Dropbox, Google, Industrial Light & Magic, Quant Finance, … • Version 3.x breaks backwards compatibility with 2.x • 2.x still most widely used, including in this course In natural sciences & engineering? • Used mainly: • As a multipurpose workflow environment for data analysis and visualisation • As “glue”, i.e. interface code, to heavy numerical kernels written in a compiled language like C/C++ or Fortran (e.g. Fluidity, ASE) • For rapid prototyping of algorithms • For non-HPC simulations • Though performance continues to improve and there are some 100% Python codes (e.g. GPAW), these are still not widely used for heavy numerics. Python characteristics • Python is a high-level language (compared e.g. to C), • Simple syntax, more easily readable code and shorter programs but • Sacrifice some performance due to abstraction overheads • Development time considered more valuable than compute time • Python is a fully-featured general purpose programming language (like C, C++, Fortran, Java, etc.) • Python supports (but does not enforce) different programming styles, e.g. object-oriented • Python is open source The Python interpreter • Python code is not generally compiled into a standalone executable, but executed by the Python interpreter, python! • Python code contained in a script file (ending in .py) can be execute by the interpreter as follows: aproeme$ cat hello.py! print(“Hello World”)! aproeme$ python hello.py! Hello World! Interactive Python • If not supplied with an input script file, the Python interpreter runs as an interactive Python runtime environment (a Python shell session) ! aproeme$ python! Interactive Python • If not supplied with an input script file, the Python interpreter runs as an interactive Python runtime environment (a Python shell session) ! aproeme$ python! Python 2.7.7 |Anaconda 2.0.1 (x86_64)| (default, Jun 2 2014, 12:48:16) ! [GCC 4.0.1 (Apple Inc. build 5493)] on darwin! Type "help", "copyright", "credits" or "license" for more information.! Anaconda is brought to you by Continuum Analytics.! ! >>>
Description: