Python language

Python is a common introductory language because it is much easier for humans to read than many other languages. The Python language is considered an interpreted language, not a compiled language. All this means is that you can run the code as you write it rather than writing all the code first and then running it. For this reason interpreted languages like Python and R have become the go to languages for data exploration and analysis.

Python variables

The first concept to understand is that of data types. The most basic of which are strings, integers, and floats. There are others, but for the time being you can get by not knowing them.


The designation for integer in Python is int. An integer is basically a number without a decimal point (also known as a whole number).

Since there are no decimal points the mathematical functions can be a bit tricky. Returned values are truncated (the decimals are removed).

Now we will introduce coding comments. I know it is a lot but stick with me because being able to put comments in the code will help me annotate the code for you. The # value can be added in code to create a comment. Comments are just that...comments for the reader. They are not read by the interpreter and therefore not converted into code.


The designation for a float in Python is float. These are numbers with decimal points. It might be hard to imagine why anyone would ever use integers instead of floats since floats make more sense when doing math. Mainly integers are used to save computer memory (RAM) when you don't need to use decimal points.

This leads to the use of decimals in mathematical functions.


The designation for string is str. Strings are basically words or text. Strings need to be surrounded by " or ' as if they were quotes.

When using strings you can even convert between data any other of the data types. Otherwise, you can convert integers to float and floats to integers. However, you cannot covert all strings to integers or floats.


The designation for booleans is bool. Boolean simply means binary, in this case True or False. This can also be thought of as 0 (False) or 1 (True).

Booleans are typically used in logical operations, such as if statements. These will be discussed later.


The next concept to understand is variables. Variables are the main building blocks of coding. They are how we store values for later use.

Here is when you can really see the utility of comments. Comments can make the difference between a good coder and a great coder. It helps because no matter how well you understand your code now...after stepping away for a while you will be happy they are there to remind you what your code is doing and why. It will also help others to understand your code when things get hard to keep track of.

This can be very confusing, but might be cleared up with a few comments

When assigning variables to other variables it is important to remember that if you change the first variable you will change the second too.
Python also has dynamic typing. This just means that we can assign a variable to any data type and Python will figure out what type it is later. In some languages you have to tell the computer what type your variable is before assigning anything to it. You don't have to worry about that here.

If you are unsure what data type you are working with you can always use the type() function.


Python has three other built-in data types: list, set, dict. These are called containers because you can put multiple things into them.


As is a common theme, a List can be thought of as exactly that...a list of items.

Pretty much anything can be put into a list. Lists will remember the order in which you out things into them. Therefore, you can access the items in the list by their order in the list starting at position 0. Accessing an item like this is called indexing. The position is called the index.

Lists can also be extended after they are initiated.

Lists are great for storing sequence data.


Sets are a lot like lists except they cannot have duplicate items. That means they can only contain unique items.

Sets can't be indexed. However, they can be extended like lists, except the method to extend a set is called add instead of append.

Sets are typically a bit faster to check if something is in than checking a list.

Sets are efficient ways to store unique items.


A dictionary, or dict, is a way to look something up given a key.

You can now lookup values by a key, similar to how we lookup values in a list with an index.


Like many programming languages Python makes use of logical operators.

Use of these operators returns a boolean.


Loops let us iterate over the values in an object.

Here we have now introduced the print statement as well. All it does is print what is inside to the screen.

i is equal to the value in the list you are currently positioned on. You can iterate over a dictionary as well


Functions allow us to put code into a box of sorts and re-use it elsewhere. Breaking up code like this is called a module. Modularity is the mark of a good coder. It makes for re-usable code that is easier to debug and understand.

This will prevent your code from getting too long and hard to follow.