Python Cheatsheet By Chloe

Python is an extremely versatile, human readable and easy to comprehend programming language.
Below are some of the basics you need to know about Python before starting, then click on the links in the drop down menu to go into more depth about each section.

print() - A in-built Python function. Allows you to output information onto a console.
i.e. The classic developer greeting:
print("Hello World")
=> Hello World
You should note that unlike JS, the semi-colon is not needed.

To write a comment within the Python code you use the hash key (#), anything written after that will not be seen by the user, only by the developers. This is handy when working on a big project with many people adding to the project so that they know what the code is doing.

Use the ... notation to code over multiple lines, as the curly brackets are not used when writing conditional statements in Python.
Python also has an indenting convention of four whitespaces, if this is not used an error will occur in your code.

When naming variables, a keyword is not needed i.e. var, let, const. Instead you name the variable and assign it to a value using the assigniment operator (=). When naming variables they should explain what the variable is used for, and two word variables should be seperated with an underscore (_).
i.e. my_name = "Chloe"

Data Types

Python uses different data types do determine what values can be applied to it and what you can do to it. It is important to be able to distinguish different data types so that you know what methods you can apply to it.

1. NUMBERS:
Any number entered into python will be interpreted as a number, which will then be determined as one of the following:
Intergers (int) - This is any number written WITHOUT a decimal place. They can be both positive and negative numbers.
Floating point numbers (float) - This is a number WITH a decimal place. They can be both positive and negative numbers.
PLEASE NOTE - 3.0 is not the same as 3. Python will interpret 3.0 as a float and 3 as an int and treat them differently.

2. BOOLEANS:
Only two possible values; True or False. In order for it to be a boolean the capital 'T' and 'F' is needed.
They are used to represent the truth values that are associated with the logical branch of mathematics.
i.e 5>8 - False
4=4 - True

Booleans can also be stored in variables.
        my_bool = 5>8
        print(my_bool)
        =>
        False
        
3. STRINGS:
Anything written within either single of double quotations. It is important to be consistent in the choice of quotations used throughout the programme.
e.g. my_string = "Lets learn Python"

4. LISTS:
A mutable(changeable) ordered sequence of elements, they can have values added, removed or replaced. Each element within a list is called an item.
They are distinguished as a list by having square brackets [].
The output will be exactly how we defined it, including brackets.
        my_list = ['orange', 'apple', 'pear', 'banana']

        print('my_list')
        =>['orange', 'apple', 'pear', 'banana']
        
5. TUPLES:
An unchangeable ordered sequence of elements, distinguished by using the ().
The output will be exactly how we defined it, including brackets.
        my_tuple = ('you', 'cant', 'change', 'a', 'tuple')

        print('my_tuple')
        =>('you', 'cant', 'change', 'a', 'tuple')
        
6. DICTIONARIES:
Pythons built-in mapping type. Constructed with curly brackets ({}). They are made up of key-value pairs which can be called upon and changed.
        my_dict = {'name':'Chloe', 'Gender':'Female', 'age':'27'}

        print(my_dict['Gender'])
        =>Female.