Python Basics 1 — Introduction

This is a part of a Python 3 tutorial series based around medical examples to teach healthcare professionals how to code in Python.

Dr. Matt, MBBS BSc
Doctors in Tech
3 min readJun 30, 2019

--

Python is one of the most powerful languages you can have in your tool kit as a healthcare professional. It is used in everything from websites to machine learning and is possibly the most popular language within data science. This article is the first article in a series aimed at teaching healthcare professionals how to code in python.

What is python

From Python’s website:

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python’s simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.

Got it? If not, in english, Python is a simple language which is easy to learn, fast to code, and modular in a way that you can import modules into your own from ‘libraries’. This can be incredibly useful as many of these libraries are designed to do complex tasks which would take a long time to create if you had to do it yourself.

First things first

You need an environment to code on. Eventually we will transition to coding from your machine, but for now we will code using an online IDE (don’t worry) called, Repl.it, follow the link to open a window in your browser.

You should have something that looks like this:

Hello World

We’re going to start with a very simple program that will print something to the console. Simple!

In Python the command to print something to the console is:

What you want to print goes between the brackets. So currently we are printing nothing. In this case what we want to print would be ‘Hello World’. In order to do this we would write the following.

Type this into your console (the white panel in the middle of your screen on Ripl.it). The press the green run button at the top of your screen. If you have done everything correctly you should see ‘Hello World’ appear in your console (the black screen to the right of the where you have written your code).

Print your name

Most of the time we don’t want to print a static phrase such as we have done above. Let’s try adding your name. For this we are going to introduce the concept of a variable. Don’t worry about what this is too much, we will discuss it more in the next tutorial. For now just know a variable is something that holds a value of some sort.

Above where your ‘print’ statement is type the following, but with your own surname.

Now adapt your print statement to the following

Now click the run button and see what happens.

If you have done it correctly, you should have had ‘Hello Dr Smith’ (or whatever name you chose) printed out in the console.

Congratulations

You have written your first program. Great work! We will build on from this in the next few weeks.

Challenge

For your first ever challenge try and prepend your first name to the print statement. To do this you should create another variable and add it to the print statement. The solution will be posted with the next tutorial.

--

--

Dr. Matt, MBBS BSc
Doctors in Tech

Medical Doctor | Medical Technology | Neurology | Published Researcher | While I have your attention, you may as well scroll down.