What is Python?

Python Logo

How does Python compare to other languages?

Python is an interpreted language, which means that the code is not compiled in advance, which makes it slower than languages like C/C++ or Fortran. Why therefore would we want to learn/use it?

  • It has a clean and simple syntax which emphasises readability
  • It can be much faster to write programs in than other languages
  • It gives detailed errors by default which makes it easier to fix bugs
  • It is easy to use for interactive analysis
  • A large ecosystem of packages for scientific analysis, including numerical analysis (interpolation, integration, clustering, FFTs, linear algebra, signal processing, stats, etc), databases, graphical interfaces, web scraping, 'big data' access, interfaces to hardware, etc.
  • It is easy to interface with C/Fortran code
  • It can interact with command-line programs, and other languages
  • Packages such as Numpy (for arrays) are written in C, which means that we get the convenience of Python and the speed of C
  • There is a strong community of friendly developers!

A growing ecosystem of packages for Astronomy

Astropy Core Package:

  • Unit conversion/handling
  • Powerful table operations and reading/writing
  • Date and time conversions
  • Celestial coordinate systems
  • Modeling/fitting
  • Common analytic functions
  • FITS file and VO table handling
  • Reading/writing many ASCII table formats
  • Convolution/filtering
  • Cosmological calculations
  • Astrostatistics

Affiliated Packages:

  • Image reprojection
  • Publication-quality image plotting
  • Machine learning
  • Photometry
  • Interface to many web services/archives (both VO and non-VO)
  • Gamma-ray data analysis
  • CCD image reduction
  • Interfaces to ds9
  • Spectroscopic analysis

and so on...

Why it called 'Python'?

Even though the Python logo has snakes in it, Python originally comes from the Monty Python comedy group!

Therefore, a lot of official Python documentation includes jokes related to the Monty Python!

A note on Python 2 vs 3

The latest version of Python is currently 3.4, but you should be aware that many (~80%) people are still using version 2.7 (the latest 2.x release). Most packages actually support Python 3, but there is inertia in using Python 3 because it requires some small changes in scripts for them to work. In this course, we will learn Python 3.x syntax directly, but I will point out later in the course what changes are required if you ever need to use the older Python 2.x.