Chapter 5-                       Data Types in Python
Numbers
As indicated, Python accommodates floating, integer and complex numbers. The presence or absence of a decimal point separates integers and floating points. For instance, 4 is integer while 4.0 is a floating point number.
On the other hand, complex numbers in Python are denoted as r+tj where j represents the real part and t is the virtual part. In this context the function type() is used to determine the variable class. The Python function instance() is invoked to make a determination of which specific class  function originates from.
Example:
Start IDLE.
Navigate to the File menu and click New Window.
Type the following:
number=6
print(type(number))    #should output class int
print(type(6.0))    #should output class float
complex_num=7+5j
print(complex_num+5)
print(isinstance(complex_num, complex)) #should output True
Important: Integers in Python can be of infinite length. Floating numbers in Python are assumed precise up to fifteen decimal places. 
Integers
These are numbers that without decimal parts, such as -2, -1, -4, 0, 8, 6 etc.
In declaring an integer, write variableName = initial value
Example:
userAge = 20
mobileNumber = 12398724
Number Conversion
This segment assumes you have prior basic knowledge of how to manually or using a calculate to convert decimal into binary, octal and hexadecimal. Check out the Windows Calculator in Windows 10, Calculator version Version 10.1804.911.1000 and choose programmer mode to convert automatically.
Programmers often need to convert decimal numbers into octal, hexadecimal and binary forms. A prefix in Python allows denotation of these numbers to their corresponding type.
Number System  Prefix
Octal    ‘0O’ or '0o'
Binary    ‘0B' or '0b'
Hexadecimal   '0X or '0x'
Example
print(0b1010101)  #Output:85
print(0x7B+0b0101)  #Output: 128 (123+5)
print(0o710)   #Output:710
Practice Exercise
Write a Python program to display the following:
Type Conversion
Sometimes referred to as coercion, type conversion allows us to change one type of number into another. The preloaded functions such as float(), int() and complex() enable implicit and explicit type conversions. The same functions can be used to change from strings.
Example:
Start IDLE.
Navigate to the File menu and click New Window.
Type the following:
int(5.3)   #Gives 5
int(5.9)   #Gives 5
The int() will produce a truncation effect when applied to floating numbers. It will simply drop the decimal point part without rounding off. For the float() let us take a look:
Start IDLE.
Navigate to the File menu and click New Window.
Type the following:
float(6)   #Gives 6.0
ccomplex(‘4+2j’) #Gives (4+2j)
Practice Exercise
Apply the int() conversion to the following:
ü       4.1
ü       4.7
ü       13.3
ü       13.9
Apply the float() conversion to the following:
ü       7
ü       16
ü       19
Decimal in Python
Example
Start IDLE.
Navigate to the File menu and click New Window.
Type the following:
(1.2+2.1)==3.3  #Will return False, why?
Discussion
The computer works with finite numbers and fractions cannot be stored in their raw form as they will create infinite long binary sequence.
Fractions in Python
The fractions module in Python allows operations on fractional numbers.
Example
Start IDLE.
Navigate to the File menu and click New Window.
Type the following:
import fractions
print(fractions.my_fraction(2.5))  #Output 5/2
print(fractions.my_fraction(4))  #Output 5
print(fractions.my_fraction(2,5))  #output 2/5
NOTE
Creating my_fraction from float can lead to unusual results due to the misleading representation of binary floating point.
Mathematics in Python
To carry out mathematical functions, Python offers modules like random and math.
Start IDLE.
Navigate to the File menu and click New Window.
Type the following:
import math
print(math.pi)   #output:3.14159….
print(math.cos(math.pi)) #the output will be -1.0
print(math.exp(10))  #the output will be 22026.4….
print(math.log10(100)) #the output will be 2
print(math.factorial(5)) #the output will be 120
Practice Exercise
Write a python program that uses math functions from the math module to perform the following:
ü       Square of 34
ü       Log1010000
ü       Cos 45 x sin 90
ü       Exponent of 20
Before tackling flow control, it is important we explore logical operators.
Comparison operators are special operators in Python programming language that evaluate to either True or False state of the condition.
Program flow control refers to a way in which a programmer explicitly species the order of execution of program code lines. Normally, flow control involves placing some condition (s) on the program code lines.