Summary
At the end of this tutorial you will have a VERY brief understanding of how the Python language works. This is ment to give you an introduction to the terminology so that you can search and try things on your own afterward.
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.
Integers
The designation for integer in Python is int. An integer is basically a number without a decimal point (also known as a whole number).
  Python
>>> 1
1
Since there are no decimal points the mathematical functions can be a bit tricky. Returned values are truncated (the decimals are removed).
  Python
>>> 2 / 3
0
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.
  Python
>>> 2 / 3 # dividing integers
0
>>> 2 * 3 # multiplying integers
6
>>> 3 % 2 # get division remainder
1
>>> 3**2 # 3 to the 2nd power
9
Floats
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.
  Python
>>> 1.5
>>> 1.5 / 1.5 # divide floats
0.0
This leads to the use of decimals in mathematical functions.
  Python
>>> 1.5 / 1.5
0.0
String
The designation for string is str. Strings are basically words or text. Strings need to be surrounded by " or ' as if they were quotes.
  Python
>>> "Hello world"
"Hello world"
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.
  Python
>>> int("1")
1
>>> float("1.5")
1.5
>>> int(1.9)
1
>>> str(1.9)
'1.9'
Boolean
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).
  Python
>>> True
True
>>> False
False
>>> True + False
1
Booleans are typically used in logical operations, such as if statements. These will be discussed later.
Variables
The next concept to understand is variables. Variables are the main building blocks of coding. They are how we store values for later use.
  Python
>>> x = 1 # x now is now equal to the integer 1
>>> x + 1 # is the same a 1 + 1
2
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.
  Python
>>> x = 1
>>> y = x
>>> x = 2
>>> y + 1
3
This can be very confusing, but might be cleared up with a few comments
  Python
>>> x = 1
>>> y = x # y is equal to x and x is 1
>>> x = 2 # x is changed to 2
>>> y + 1 # y is still equal to x
3
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.
  Python
>>> x = 1 # x is an integer
>>> x = "1" # x is a string
If you are unsure what data type you are working with you can always use the type() function.
  Python
>>> x = 1
>>> type(x)
int
>>> x = "1"
>>> type(x)
str
Containers
Python has three other built-in data types: list, set, dict. These are called containers because you can put multiple things into them.
List
As is a common theme, a List can be thought of as exactly that...a list of items.
  Python
>>> x = ["apples", 'grapes', "bananas"]
>>> x = [1, 2, 5]
>>> x = ["a", 1.2, 4]
>>> x = [["a", "b","c"], 1, 2, True]
>>> x = [x, 1, 2]
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.
  Python
>>> x = ["a", "b", "c"]
>>> x[0]
a
>>> x[1]
b
>>> x[2]
c
>>> x[3]
IndexError
Lists can also be extended after they are initiated.
  Python
>>> x = [1, 2, 3]
>>> x.append(4)
>>> x
[1, 2, 3, 4]
Lists are great for storing sequence data.
Set
Sets are a lot like lists except they cannot have duplicate items. That means they can only contain unique items.
  Python
>>> x = set([1, 2, 3, 3])
>>> x
{1, 2, 3}
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.
  Python
>>> x = set(['a', "b", "a", 'c'])
>>> x.add('d')
>>> x
{'a', 'b', 'c', 'd'}
>>> x.add('b')
>>> x
{'a', 'b', 'c', 'd'}
Sets are typically a bit faster to check if something is in than checking a list.
  Python
>>> x = set(['a', 'b', 'c'])
>>> 'a' in x # returns a boolean
True
>>> "A" in x
False
Sets are efficient ways to store unique items.
Dictionary
A dictionary, or dict, is a way to look something up given a key.
  Python
>>> x = {'word1': "definition1", "word2":"definition2"}
You can now lookup values by a key, similar to how we lookup values in a list with an index.
  Python
>>> x = {'word1': "definition1", "word2":"definition2"}
>>> x["word1"]
definition1
>>> y = 'word2'
x[y]
>>> definition2
Logic
Like many programming languages Python makes use of logical operators.
  Python
>>> 1 < 2
True
>>> 1 <= 1
True
>>> 1 > 2
False
Use of these operators returns a boolean.
  Python
>>> x = 1 < 2
Loops
Loops let us iterate over the values in an object.
  Python
>>> x = [1, 2, 3] # List
>>> for i in x:
... print(i)
1
2
3
Here we have now introduced the print statement as well. All it does is print what is inside to the screen.
  Python
>>> print("hello world")
hello world
i is equal to the value in the list you are currently positioned on. You can iterate over a dictionary as well
  Python
>>> x = {'word1': "definition1", "word2":["definition2", 1]}
>>> for z in x:
... print(z) # print key
... print(x[z]) # print value
word1
definition1
word2
[definition2, 1]
Functions
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.
  Python
>>> def multiply(x, y):
... z = x * y
... return z
>>>
>>> q = multiply(2, 3)
6
This will prevent your code from getting too long and hard to follow.
  Additional
There are many thing not covered in this tutorial. Here are just a few.
  byte strings
  tuples
  List comprehensions
  While loops
  Data class
  Objects