Python is a dynamic, strongly typed, object-oriented programming language.
from IPython.display import Image
Image(filename='confused-cat.jpg')
Courtesy of flicky user sfroehlich1121.
Before we go into what the above means, note that there is a strong, and growing, Python community in Astronomy - for instance
X-ray astronomy (CIAO)
optical/ground-based astronomy (PyRAF)
radio (CASA)
Solar astronomy (SunPy)
It's also a useful "transfereable" skill, for those of you that end up moving out of Astronomy.
Once you've got the hang of Python - and found out that many questions you have have already been answered on Stack Overflow - the trick is in finding the package you need, rather than writing your own code. cough cough astropy cough cough
You should also be aware of R
- The R project for Statistical Computing -
which is not Python, but is important as Astronomy moves into the era of
Image(filename='big_data.png')
courtesy of the internetz.
always active or changing
having or showing a lot of energy
of or relating to energy, motion, or physical force
At least that's what Merriam-Webster says.
a = 23
print("The answer is " + str(a))
b = a + len("confused kitty is confused")
print("The answer is now " + str(b))
a = "Goooooooooooooollllll"
print("The answer is now " + a)
The answer is 23 The answer is now 49 The answer is now Goooooooooooooollllll
Things to note:
you can define variables when you need them
you do not need to define the "type" of a variable
you can change what you store in a variable (one moment it's an integer, then it's a string)
The operations you can do depend on the "type" of the variable (or constant).
len("This is a string")
16
len(23)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-3-c9328ce85f6c> in <module>() ----> 1 len(23) TypeError: object of type 'int' has no len()
These error messages look confusing at first, but you will quickly learn what to look for: ignore everything until the last line!
On the last line you'll see "BlahError: hopefully something more informative than blah
", which
tells you the type of error (so in this case, it is a "TypeError
"), and then
an optional string giving more information, which in this case says that you have tried
to use len
on something that doesn't have a length.