top of page

Python Tutorial for Beginners

  • Writer: Ian Vicino
    Ian Vicino
  • Jul 10, 2023
  • 4 min read

As I mentioned in the featured article on this site, I learned Python after being introduced to it by a friend and subsequently finding a textbook online which I read cover to cover. This textbook was my introduction to Python. Then I searched for tutorials online to learn intermediate and advanced Python projects I could attempt to improve my coding skills. I want to help you, my reader, learn what I learned, to attempt Python coding projects undreamed of before.

If you have never coded ever in your life but are interested to begin learning, you have come to the right place. This tutorial is intended to teach you how to get your feet wet and begin coding immediately. Trust me, once you see your code runs successfully and produce an output, you will never look at a computer the same again. If you begin on this journey you may soon be able to code your own artificial intelligence algorithms or, as can be seen in my latest article “Qlearning-MakingAGamePlayItself”, you might decide to develop a game that can play itself to investigate what it means to be intelligent. You might decide to automate a tedious repetitive task or change your career trajectory. To borrow from a well known phrase, every journey begins with a first step and I hope this tutorial will be that first step into the wonders of development.

By the end of this series of tutorials I will publish you should have not only programmed your first Python application but learned about some of the different data types available to your development journey. You will have learned about for-loops and ifstatements and developed methods to automate some of your repetitive tasks on a computer. The other benefit of this series of tutorials is you can provide feedback so I may improve as an instructor. These tutorials can be molded directly by you, the reader. Let us begin on our journey together.

First Step to Learning How to Code in Python


(Picture above) Windows Powershell window – an advanced command prompt available on Windows systems, introduced in 2006 with Windows XP. A Terminal is the same thing as a command prompt for an Apple computer.


To begin coding with python, most textbooks or lessons begin by having you download Python and begin coding using your command prompt/terminal. Lucky for you, this tutorial series will not be using the command prompt/terminal, instead we will be using an interactive development environment, or IDE, created by google and available free online called Google Colaboratory (https://colab.google/). That way anyone can start coding almost immediately.

Google Colaboratory (google colab) allows you to get your fingers on the keyboard and begin programming quickly so when you are comfortable and understand more about how a computer works you can download and use the command prompt/terminal or a different IDE to continue coding. (I like to use Visual Studio Code as my IDE) But that is enough about the command prompt/terminal, we won’t be messing with that here. Lets get you coding using Google Colab.

Using Google Colab

If you have a gmail account you can use that to easily sign into google colab by clicking on this link: https://colab.google/ and pressing on the New Notebook link. If not you will have to create an account with google to begin using google colab, but trust me it is worth it. Not only will we be using google colab to have you start programming, but for future advanced machine learning projects you will have access to a graphical processing unit (GPU) you can use to train your machine learning algorithms.

After you have logged into google colab you should see a screen similar to this (NOTE: your screen will not be in Dark mode, but otherwise it should look very similar to this):

This is the introduction screen to google colab. To begin programming open up a new notebook by pressing File>New Notebook. (If you have not yet signed in to google you may be prompted to sign in now.) The new notebook will open on a new tab of your internet browser. It will have an empty entry box with a Play button to the left. This can be seen in the image below:



The empty box is where you will program your first line of code. Type print(“Hello World!”) directly into the box and press either the play button or shift+enter. This will run the code and open a new entry box to write new code into it. You should see the output below the entry box (see example below).



If you do not see that output you have encountered your first bug. Congratulations! It will be the first of many bugs. The problem probably occurred due to a typo. You might have either missed a quotation mark or capitalized the P in print. If you read the error statement it should help you fix the bug. Actually the error statements are very important and they will be discussed in the next tutorial. Finding and fixing these error is called troubleshooting.

Congratulations!!! You have just programmed your first line of code, and received a successful output, you may have even had your first foray into troubleshooting. Well done! You have also used your first data type in your programming, a string. I will go into more on that as well during the next tutorial, but suffice it to say a string is a phrase surrounded by quotation marks, either single or double quotation marks. With python you can use either single or double quotation marks. Try it out, change the double quotation marks for single quotation marks, or visa versa, and play around with the code. Attempt to get an error to see what that looks like. That is the best way to learn how to code, play around with it yourself and make mistakes.

That is the end of this lesson. As I stated above, the next lesson I will go into error statement, troubleshooting and a discussion of the different data types available within computation. Do not forget to leave a comment about how the tutorial went, if you had any issues, or any constructive criticism you might have. Also, remember to subscribe so you don’t miss the next lesson as soon as it is posted, or the other topics I plan to write about including the current position of AI within society, how computers can help biologists find new discoveries, and what is going on with chatGPT.

Comments


bottom of page