Introduction to scientific programming

Ahmed Ammar and Hassen Ghalila

Tunis Faculty of Sciences, University of Tunis El Manar- Tunisia

In [1]:
# This gives the last run:
import time
print(time.ctime())
Tue May 16 14:30:43 2017

Python language

[Python] (http://www.python.org/) is a modern object oriented programming language dedicated to general use.

General characteristics of Python:

  • Simple: Easy to read and easy to learn with a minimalist syntax.
  • Concise and expressive: less lines of code with less bugs and easier to sustain.

Technical details:

  • Dynamically Typed Language: No need to define the variable types, the argument types or the function types.
  • Automatic Memory Management: No need to explicitely allocate or deallocate the memory for variables and arrays. Python automatically manage bugs.
  • Interpreted: No compilation needed, Python interprets and runs directely line codes.

Advantages

  • The main advantage is the easy of programming and flexibility of use that minimize the time needed to develop, debug and maintain the code.
  • Language well conceived that push the developer toward the good programming practices:
    • Modular, oriented object, allows the encapsulation and the reuse of the codes. This often results in a more transparent, maintanable and bug-free code.
    • Documentation and command helps well implemented
  • Many standard libraries and packages add-on.

Disadvantages

  • Since Python is a dynamically typed and interpreted programming language, execution of python code can be slow compared to other languages such as C and Fortran. This could be bypassed by generating the app.
  • Global contributors make it highly decentralized with many libraries, environments and documentations. This could make it difficult to start.

Installating Python environment

Anaconda CE. Anaconda Community Edition is free.

Documents and websites for Python

  • Python : The official Python website.
  • Python tutorials : The official Python tutorials.
  • Think Python : ''How to Think Like a Computer Scientist'' by Allen B. Downey (free book).
  • Python Course : This website contains a free and extensive online tutorial by Bernd Klein, well suited for self-learning.

Github lessons

Python version and libraries

In [2]:
print ("\t\t Current System")
import sys
print("System :\t\t",sys.platform)
import platform
print(platform.platform())
print("Computer:\t\t",platform.machine())
print("Python version:\t",sys.version)
import IPython
print("IPython version:\t",IPython.__version__)
import numpy
print("Numpy version:\t",numpy.version.version)
import scipy
print("Scipy version:\t",scipy.version.version)
import matplotlib
print("Matplotlib version:\t",matplotlib.__version__)
		 Current System
System :		 darwin
Darwin-13.4.0-x86_64-i386-64bit
Computer:		 x86_64
Python version:	 3.5.1 |Anaconda 4.1.0 (x86_64)| (default, Jun 15 2016, 16:14:02) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)]
IPython version:	 4.2.0
Numpy version:	 1.11.0
Scipy version:	 0.17.1
Matplotlib version:	 1.5.1
In [ ]: