Integers: Like in math, integers in computer programming are whole numbers that can be positive, negative, or 0 (…, -1, 0, 1, …). An integer can also be known as an int. As with other programming languages, you should not use commas in numbers of four digits or more, so when you write 1,000 in your program, write it as 1000.
Floating-Point Numbers: A floating-point number or a float is a real number, meaning that it can be either a rational or an irrational number. Because of this, floating-point numbers can be numbers that can contain a fractional part, such as 9.0 or -116.42. In general, for the purposes of thinking of a float in a Python program, it is a number that contains a decimal point.
The Boolean data type can be one of two values, either True or False. Booleans are used to represent the truth values that are associated with the logic branch of mathematics, which informs algorithms in computer science.
A string is a sequence of one or more characters (letters, numbers, symbols) that can be either a constant or a variable. Strings exist within either single quotes ' or double quotes " in Python, so to create a string, enclose a sequence of characters in quotes:
'This is a string in single quotes.'
"This is a string in double quotes."
A list is a mutable, or changeable, ordered sequence of elements. Each element or value that is inside of a list is called an item. Just as strings are defined as characters between quotes, lists are defined by having values between square brackets [ ].
A list of integers looks like this: [-3, -2, -1, 0, 1, 2, 3]
A list of floats looks like this: [3.14, 9.23, 111.11, 312.12, 1.05]
A list of strings: ['shark', 'cuttlefish', 'squid', 'mantis shrimp']
A tuple is used for grouping data. It is an immutable, or unchangeable, ordered sequence of elements.
Tuples are very similar to lists, but they use parentheses ( ) instead of square brackets and because they are immutable their values cannot be modified.
A tuple looks like this: ('blue coral', 'staghorn coral', 'pillar coral')
max() and min() When we work with tuples composed of numeric items, (including integers and floats) we can use the max() and min() functions to find the highest and lowest values contained in the respective tuple.
The dictionary is Python’s built-in mapping type. This means that dictionaries map keys to values and these key-value pairs are a useful way to store data in Python. A dictionary is constructed with curly braces on either side { }.
Typically used to hold data that are related, such as the information contained in an ID, a dictionary looks like this:
{'name': 'Sammy', 'animal': 'shark', 'color': 'blue', 'location': 'ocean'}
Common functions: len() , max() , min() , sorted() , sum() , type() and slicing can be used for most of the types above.
Common methods: .upper(), .lower(), .strip(), .replace(), .split(), .join() and slicing can be used for most of the types above.
Common methods for list: .append() , .remove() , .count() , .clear() ...
Common methods for dict: .keys() , .values() , .clear() ...