Python for Science

Running Python Code

Let's get Python up and running.

Hello, World!

As per tradition, let's start by creating a "Hello, World!"-program. This is a simple program that just prints (i.e. displays) the string (i.e. text) "Hello, World!" somewhere, often a terminal.

To stay organized you should first create a folder in a suitable location on your computer and name it something nice. I've created a folder on my computer called my-python-stuff.

  1. Open VS Code
  2. In VS Code, open the File menu and select Open Folder...
  3. Find and choose the folder you just created.

Now we're going to create a Python file with some code and run it.

TODO: Add screenshots or video.

  1. Click the New File... icon on the left (hover over MY-PYTHON-STUFF)
  2. Create a new file called hello.py
  3. Add the line print("Hello, World!") to the file and save
  4. Now VS Code will hopefully notice that you've added a Python file and ask if you want to install the Python extension. Do that.
  5. If it says "Python 3.11.0" in the bottom bar of the GUI (graphical user interface), you're good. If it instead says something like "Select interpreter", click that and manually locate the Python interpreter on your file system.
  6. In the top bar, click "View" -> "Terminal"
  7. Type python hello.py and press ENTER (if you have a Mac remember that you might have to write python3 instead)

Congratulations! You ran code!

Next: Syntax