Basic types and their use in Pythonintegers 

Whole numbers from negative infinity to infinity, such as 1, 0, -5, etc.

Integers or any number negative or positive without decimals can be assigned variables. You can name them anything. You can work with integers directly or assign them to variables. By work I mean you can add them, subtract them, multiply them, divide them, use parenthesis which is useful for order of operations and you can also call calculate powers and remainders. Retainers are cool because they are useful for loops and other operations. Power values are cool because they can also be used in square roots. So in a few words, standard math operations with some useful twists.

float 

Float means “floating point number,” any rational number, usually used with decimals such as 2.8 or 3.14159.

When you do math with integers, your computer interprets values as integers so you will never get a float unless you specify it. To specify, you can just add a decimal point or you can write whatever number “n” like this “float(n)”. When you do math with floats, your result will always be a float. It is important to note that when you mix strings and floating points, Python will always return a float. 

You can also turn a float into a integer value using “int(4.0)”

strings 

A set of letters, numbers, or other characters (!,&,%,#). 

Strings are sequential collections, so items in the collections are ordered.

Depending on which version of Python you are using, strings will be inside single(”) or double quotation marks (“”). In Python 3 strings will also be inside quotation marks and those quotation marks will be inside parenthesis. Strings can also be added (like integers and floats) using +’s or commas, this is called concatenation.

They can be assigned as a value to add or print or both. Integers and characters can be converted into strings by using str(). 

lists 

 x=[1,2,3]  

look at the square brackets!

Lists are sequential collections, so items in the collections are ordered.

 Sometimes regarded as the most powerful data structures in Python while simply being sequences of stuff. You can call them “x” or “sushi”, so when you run it its elements will be used. You can evaluate each element of the list by calling x knowing the position of the element you need. You can also change an specific element of your list, mixing data types and putting other lists within your list. Variables are your friend, a new variable “pizza” can refer to your existing variable “x” which has your list and make changes on your elements (as well as other useful things). To copy lists, not refer to them, you can write pizza = x[:]. This specifies which elements you want to have and copies them, this notation is cool because it lets you choose a range (from up to but not including). 

tuples 

Tuples are sequential collections, so items in the collections are ordered.

A list with a fixed number of elements. ie x=(1,2,3) parentheses makes it a tuple.

Tuples are created the same way lists are that is, they are declared like this x=(). In Python Tuples are generally seen as a clean way of storage since they are memory efficient and not adjustable but this advantage can also be seen as inflexible 

dictionaries 

A type with multiple elements i.e. x = {1: ‘a’,’b’: 2,3: 3} where you address the elements with, e.g., a text.

Dictionaries basically bind a key to a value,. One of its characteristics is their lack of order in sorting data, so dictionaries are not sequential collections like lists, strings and tuples. Some of the possible values in dictionaries can be range from lists to functions. To create a dictionary you can do the following x = {}. To reference a value in the dictionary you can print it by calling they key so 

using the example above, if you print x[1] you will get the value of the key 1 which is “a”.

CC BY 4.0 Mastery09 by 5nbpppkkyj is licensed under a Creative Commons Attribution 4.0 International License.