In true Computer Science fashion, we are going to start with the fabled “Hello, World!” program.
For this tutorial, I do not want to make you download an install programs, so instead we are going to be using Python Anywhere which provide you with a free cloud based environment where you can practice and learn your new python skills without having to go through the process of installing and maintaining Python installations which only adds stress and doesn’t really teach a lot this early.
We will cover the different types of Python versions, IDEs (Integrated Development Environment) and other tools to aid you in more advanced Python Development in later tutorials.
If you haven’t done it, please go to pythonanywhere.com and create your free account so you can start working with Python files.
How to run a Python Program?
There are two ways to run Python code, the first one is to open the Python Interpreter directly and enter the lines of codes manually one by one. However, we are going to be writing Python files (.py file extensions) and then running the file which contains the code we wrote into it.
Creating a new file in Pywhon Anywhere.
Once you are logged in and you can see the dashboard view, head over to the FILES tab on the top right.
Once you are on the Files Tab, find the field labeled “New Filename” and type “hello_world.py” and click on the New Empty File button.
This should bring a new text editor page that looks like the screenshot below. From there, you will write, modify and run your code. By default, Pythonanywhere will run Python 3.4 by default, but there are other versions available that you can configure.
Even though the file is empty, please hit the “run” button on the top, this will run the “hello_world.py” file, but since there is nothing in it, the output will be blank.
On of the cool things about using Python Anywhere, is that after you run a file in this manner, you will get a Python Interactive Shell in the bottom that will allow you to further play with the environment that was already created.
Finally Hello World!
When a Python file is run, it goes through each line and executes the code there, one at a time, until it is completed, so we are going to type the following in the first line of our empty “hello_world.py” file.
After writing that, click the Run button on the top right, this will save your file, and run the file. You should see the following:
Congratulations! You just wrote your first application using Python. In our next tutorial, we will cover how to define functions, variables, arithmetic operators, and types of objects like Strings, Integers, Characters, Etc.