Member-only story
A Physicist’s Guide to Lists in Python
Physics isn’t just physics. You have to do a lot of other stuff too — like reading, writing, math, drawing, communicating…and yes…programming.
For me, I prefer to use python. OK, I really like Glowscript VPython. It’s basically python but with some pre-loaded modules that has stuff to handle vectors, 3D objects, graphs and more. Yes, it’s my favorite. Oh, and it runs in a web browser too.
Here is a List
I previously created an introduction to functions in python, so now it’s time for lists. In python, lists are sort of like a list you make of your groceries. Let’s just make a simple list. Check this out (code is online).
Here is the output:
There you go. A list. Here are some notes:
- You can name a list as you would any python variable. It must be a unique name and it can’t start with a number.
- The list is created by using square brackets [].
- The items in the list are separated by commas.
- The list items can be anything. They don’t have to be just numbers, they can be a mix of stuff.