Run your first Python code

Background

At this point you have successfully installed Python on your computer using the Miniconda distribution. You're ready to run some Python code.

If you've programmed before, you may want to skip this and go straight to "Write your first Python program". If you're wondering what python code looks like, then read below.

The most basic way to write/run python code is using the python interpreter directly from Terminal/Command Prompt.

The Steps

  1. Open Terminal/Command Prompt
  2. Type python, to start the python interpreter

    • Your terminal should now look something like this:

    python-interpreter-1

  3. Type x = 1 and hit enter

    • You've just run your first python code!! Pretty anti-climactic, huh? It may seem like nothing happened. What you've done is created a variable x and stored the integer 1 in that variable.

    python-interpreter-2

  4. Type y = 2 and hit enter python-interpreter-3

  5. Type z = x + y and hit enter

    • As I said in the intro article, if you understand basic algebraic concepts, then you can learn python. If x = 1 and y = 2, what does z equal?

    python-interpreter-4

  6. To see what z is now storing, type print(z) and hit enter. Alternatively, you can just type z and hit enter. Your terminal should now look like this:

    python-interpreter-5

You've run your first python code! See, not so scary. One thing you may notice is there's no way to save the code that you've just written.

In the next post, we'll cover a more realistic/useful way to write, save and execute python code.


Next post: Write your first Python program

Previous post: Install Python on your computer