Member-only story
A Physicist’s Guide to Functions in Python
Maybe you are a physicist and maybe you want to use python. Well, then this is for you. OK, let’s just jump right in.
Introduction to Functions
What is a function in python? Honestly, it’s a lot like a mathematical function. So, let’s just start with a function (totally just making up something here).
This basically like a box that you feed a number into and it spits out some other number. But I assume you already know about mathematical functions. You want to know about python functions.
Well, here’s the surprise — at a certain level, a python function is the same as a math function. OK, let’s just jump into python. Technically, I’m going to be using Glowscript. This is an online version of python with some extra stuff added (like vectors, graphing, and 3D visualizations). Trust me, it’s great.
So, let’s make a python function that does the same thing as this mathematical function. Here is the code and then I will make some comments (also, the code is online too so you can edit it and stuff).
Here is the output when you run it.