About Python#
“Python has gotten sufficiently weapons grade that we don’t descend into R anymore. Sorry, R people. I used to be one of you but we no longer descend into R.” – Chris Wiggins
What’s Python?#
Python is a general-purpose programming language conceived in 1989 by Dutch programmer Guido van Rossum.
Python is free and open source, with development coordinated through the Python Software Foundation.
Python has experienced rapid adoption in the last decade and is now one of the most commonly used programming languages. It has a large and supportive user community, especially in the scientific and data science domains. Python is beginner-friendly and routinely used to teach computer science and programming in top computer science programs.
Python for Scientific Programming#
Python has become one of the core languages of scientific computing.
It’s either the dominant player or a major player in machine learning, data science, astronomy, chemistry, computational biology, and meteorology.
Textbooks and Tutorials#
Our favorite Python textbooks/tutorials include:
A Whirlwind Tour of Python by Jake VanderPlas: highly recommended for everyone. It’s worth reading even if you are already familiar with Python. We will cover some of the materials in the course.
Python Data Science Handbook also by Jake VanderPlas. It covers more advanced packages such as
pandas
.Learn Astropy tutorials.
Of course, when you encounter a problem, you can always ask for help on Stack Overflow, ask us, ask your friends, or ask your favorite large language model.
In addition, Princeton offers a number of courses on Python, from introductory to advanced. Some resources are pre-recorded but there are also courses NEED SCHEDULE HERE!
Popularity#
The following figure (made by Yuan-Sen Ting) shows the evolution of programming languages used in astronomy papers over time. It’s clear that Python has become the dominant language in the field (whereas IRAF and IDL were dominant in the past). Python is now the number one choice not only because it is easy to learn, but also because it has a huge number of libraries that fit the needs of astronomers (especially observational astronomers!!).
You will have a chance to use different Python libraries in the course, and some of them will continue to be useful in your future research.
Features#
Python is a high-level language suitable for rapid development. It supports multiple programming styles are supported (procedural, object-oriented, functional, etc.). We will (probably) use all these styles in the course.
Code Style#
It is very important to write clean and readable code. We highly recommend you to read this Python Style Guide to get a sense of what good Python code looks like. As you go through the course materials, you will see how we write code and you will be able to develop your own style based on these guidelines.
What to do if your code doesn’t work?#
Ask us for help, that is what we are here for.
Ask Google, Stack Overflow, or your favorite search engine. New programmers often make the mistake of thinking that they need to solve every problem from scratch. In reality, most programming problems have been encountered by someone else before. Don’t feel embarrassed by the mistakes you make. Everyone makes mistakes when they are learning to program (including the instructors – they still suffer a lot now).
Ask your classmates. They are likely to have encountered the same problem.
Ask large language models (such as GPT or Claude). These models now are really good at debugging code.
Try the AI assistant on Google Colab.