>>> x +2# Sum of two variables7>>> x -2# Subtraction of two variables3>>> x *2# Multiplication of two variables10>>> x **2# Exponentiation of a variable23>>> x %2# Remainder of a variable1>>> x /float(2)# Division of a variable2.5
1.3 Types and Type Conversion
Function
Example
Explanation
str ()
‘5’, ‘3.45’, ‘True’
Variables to strings
int()
5, 3, 1
Variables to integers
float()
5.0, 1.0
Variables to floats
bool()
True, True, True
Variables to booleans
2. Lists
>>> a ='is'>>> b ='nice'>>> my_list =['my','list', a, b]>>> my_list2 =[[4,5,6,7],[3,4,5,6]]
2.1 Selecting List Elements
Subset
>>> my_list[1]# Select item at index 1>>> my_list[-3]# Select 3rd last item
Slice
>>> my_list[1:3]# Select items at index 1 and 2>>> my_list[1:]# Select items after index 0>>> my_list[:3]# Select items before index 3>>> my_list[:]# Copy my_list
Variables and Data TypesVariable Assignment>>> x = 5>>> x5Calculations with VariablesSum of two variables>>> x + 27Subtraction of two variables>>> x - 23Types and Type ConversionListsSelecting List Eleme