Data Types

Types

Data in python can take the following types:

Data Type Description
int An integer.
float A floating point number (e.g. a decimal).
list A list of items comma separated inside square brackets.
tuple A special type of list that cannot be changed.
str A series of characters and can be treated like a list of characters.
bool A Boolean value that is either true or false.
dict A dictionary of key: value pairs.
set An unordered selection of unique items defined with curly brackets.

Conversion

Python provides some built in functions in order to convert between data types.

Function Description
int() Converts to an integer.
float() Converts to a float.
hex() Converts a number to a hexadecimal string.
oct() Converts a number to an octal string.
tuple() Converts to a tuple.
set() Converts to a set.
list() Converts an iterable to a list.
dict() Converts a list or tuple of key-value pairs into a dictionary.
str() Converts a number into a string.

Operators

When undergoing mathematical equations, the following operators can be used.

Operator Description
** Exponent.
// Floor division.
% Modulo.
+= Update a variable by adding a certain value.
-= Update a variable by subtraction of a value.
*= Update a variable by multiplication of a value.
/= Update a variable by division of a value.
**= Update a variable by exponent of a value.
%= Update a variable by modulo of a value.
//= Update a variable by floor of a value.
== Equals.
!= Not equal to.
> , >= Greater than, greater than or equal.
< , <= Less than, less than or equal.