Integer and float types
# integer number represents numeric number from -infinity to +infinity
var1 = 10
print(var1)
var2 = -10
print(var2)
# verify type for integer number
print(type(var1))
# float number represents floating point number, you need
#to add . (dot) to seperate integer part from fraction
var3 = 10.0
var4 = -10.22
print(var3, var4)
# verify type for float number
print(type(var4)) |
# integer number represents numeric number from -infinity to +infinity
var1 = 10
print(var1)
var2 = -10
print(var2)
# verify type for integer number
print(type(var1))
# float number represents floating point number, you need
#to add . (dot) to seperate integer part from fraction
var3 = 10.0
var4 = -10.22
print(var3, var4)
# verify type for float number
print(type(var4))
Python math operators to manipulate numbers
# arithmetic operators for integer numbers
varInt = 33
# addition
print("Integer addition: varInt + 10")
print( varInt + 10)
# substraction
print("Integer substruction: varInt - 10")
print( varInt - 10)
# multiplication
print("Integer multiplication: varInt * 10")
print( varInt * 10)
# power
print("Integer power: varInt**2 == varInt * varInt")
print( varInt**2)
# division
print("Integer division: varInt / 10")
resInt = varInt / 10
print( resInt)
print( type(resInt))
print( type(varInt))
# arithmetic operators for float numbers
varFloat = 33.33
# addition
print("Float addition: varFloat + 10")
print( varFloat + 10)
# substraction
print("Float substruction: varFloat - 10")
print( varFloat - 10)
# multiplication
print("Float multiplication: varFloat * 10")
print( varFloat * 10)
# division
print("Float division: varFloat / 10")
print( varFloat / 10)
# power
print("Float power: varInt**2 == varInt * varInt")
print( varFloat**2.2) |
# arithmetic operators for integer numbers
varInt = 33
# addition
print("Integer addition: varInt + 10")
print( varInt + 10)
# substraction
print("Integer substruction: varInt - 10")
print( varInt - 10)
# multiplication
print("Integer multiplication: varInt * 10")
print( varInt * 10)
# power
print("Integer power: varInt**2 == varInt * varInt")
print( varInt**2)
# division
print("Integer division: varInt / 10")
resInt = varInt / 10
print( resInt)
print( type(resInt))
print( type(varInt))
# arithmetic operators for float numbers
varFloat = 33.33
# addition
print("Float addition: varFloat + 10")
print( varFloat + 10)
# substraction
print("Float substruction: varFloat - 10")
print( varFloat - 10)
# multiplication
print("Float multiplication: varFloat * 10")
print( varFloat * 10)
# division
print("Float division: varFloat / 10")
print( varFloat / 10)
# power
print("Float power: varInt**2 == varInt * varInt")
print( varFloat**2.2)
Size of numbers in python
from sys import getsizeof
# typical integer variable
varInt = 10
# size of integer in bytes
print( getsizeof(varInt))
# large integer variable 100 power to 100
varInt = 2**29
print(varInt)
# size of larger integer variable
print( getsizeof(varInt))
# typical float variable
varFloat = 10.0
# size of typical float in bytes
print( getsizeof(varFloat))
# typical float variable with very low fraction
varFloat = 10.00000000000000000000000000000000000001
# size of typical float with low fraction in bytes
print( getsizeof(varFloat))
# large float variable
varFloat = 2.0**100
print(varFloat)
# size of large float in bytes
print( getsizeof(varFloat)) |
from sys import getsizeof
# typical integer variable
varInt = 10
# size of integer in bytes
print( getsizeof(varInt))
# large integer variable 100 power to 100
varInt = 2**29
print(varInt)
# size of larger integer variable
print( getsizeof(varInt))
# typical float variable
varFloat = 10.0
# size of typical float in bytes
print( getsizeof(varFloat))
# typical float variable with very low fraction
varFloat = 10.00000000000000000000000000000000000001
# size of typical float with low fraction in bytes
print( getsizeof(varFloat))
# large float variable
varFloat = 2.0**100
print(varFloat)
# size of large float in bytes
print( getsizeof(varFloat))