Learning Python: Data Types

Summary of Python Data Types

Name Type Description Example
Integers int Whole Numbers 20
Floating Point float Numbers with decimal points 2.5
String str Ordered sequence of characters 'hello'
Lists list Ordered sequence of objects ['hello', 2.5, 50]
Dictionaries dict Unordered key:value pairs {"k1":"v1", "k2":"v2"}
Tuples tup Ordered immutable sequence of objects ("Jack",20,10.2)
Sets set Unordered collection of unique objects {"a","b"}
Boolean bool Logical value indicating True or False True

Numbers in Python

In Python there are two main number types: Integer and Floating Point numbers. Integers are whole numbers whereas floating point numbers have a decimal.

Basic Maths

2 + 3    # Addition
2 - 1    # Subtraction
2 / 2    # Division
2 * 4    # multiplication

7 / 4    # Mod Operator - returns the remainder, thus in this case will return 3
3 ** 5   # Indices - 3 to the power of 5

Other Notes

0.1 + 0.2 - 0.3 doesn't equal 0?

This is due to floating point accuracy and the ability of computers to represent numbers in memory.