Home Getting Started With Python
Post
Cancel

Getting Started With Python

Where to begin with Python

In this tutorial you will learn to install and run Python on either Mac, Windows, or Linux.

Python is able to run on multiple platforms as it is a cross-platform language. Best of all is that it is free and open source! We love free and open source. Now the only thing about Python is that there are versions Python 2 and Python 3. For This tutorial we will be using Python 3. Mac has Python 2 preinstall but you can still install Python 3 and hopefully Apple will turn everything over to Python 3 in a future update. It is also always a good idea to update the version of Python you have to the current version.


How to run Python

So first we need to see which version of Python we have on our computer. For this we will be using command line. Do not be afraid, command line is just like using a computer but you do not have a mouse. I will have a tutorial on how to get more comfortable with the command line at a later date.

  1. First open your command line prompt.

    name of picture

  2. Then type python --version. This will print out the version you have for Python 2.

    name of picture

  3. To see if you have Python 3 installed then you can type python3 --version.

    name of picture

See terminal is not all that bad! It is actually pretty fun. Next we will use the terminal to do some super basic Python writing! Super basic like 2+2 just to give you a taste and then we will move into installing an Integrated Development Environment, also called an IDE.

  1. Open up your command line prompt again. Then type python3 press enter. That is if you had a version appear for Python 3 show. If you did not then just type python and press enter.

    name of picture

  2. Then type x=2 press enter and type y=2 press enter.

    name of picture

  3. Then we will add the x and y by typing z=x+y then press enter.

    name of picture

  4. Now you have told the computer to take the value you have x set as, which in this case is 2. Then take the value you set for y and add them together. This number is set to the variable z and we will talk more about variables later.

  5. Next type print(z) and press enter.

    name of picture

  6. Ta-Da! You have now have 4 on your screen! Python and really most programming languages are fundamentally this easy. Though Python is even easier to learn due to its scripting ability.

  7. To get out of Python type exit() and press enter.


Installing an IDE

The purpose of installing an IDE is to provide an environment that will help you code. My personal opinion is that an IDE should come light weight which basically means that you only have what you need installed.

  1. We will be using Vistual Studio Code.

  2. Install VSCode to your computer.

  3. Create a folder to hold all your wonderful Python programs!

  4. Open up VSCode if you have not done so already. This is what you should see.

    VSCode first time

  5. Next is to click the file button on the top left and side of the window. Then click Open Folder. Go to where you made your Python folder and select it.

    Opening folder

  6. After that you will want to click the little button that looks like a file with a plus symbol to the right of your folder. Then name your first program helloworld.py.

    Naming first program

  7. Now you should see a popup in the bottom right and corner asking to install python 3 if you do not already have it installed. Click this and it will install it and it will automatically select it as your interpreter. An interpreter is what executes what we write in the IDE which I like to call “human code” because we are able to read it. Then the interpreter takes our code and directly executes the code without having to translate it to a machine language.

    Installing python 3

  8. When you type print() then hover over it, you will get a tool tip on how you can use print. This is the power of an IDE. They help you out when you mess up typing something or help you learn what can they can do.

    Using print

  9. In your program you want to type print("hello world").

    Code for hello world

  10. Then press the green arrow in the top right hand corner. Now you should see a screen popup at the bottom of your screen that says hello world.

    Running program

Congrats!! You just made your first Python program!

This post is licensed under CC BY 4.0 by the author.