Python Number

Working with Numeric Data with Python - Integer and Float

num_int = 7
num_float = 5.3

print(type(num_int)) # <class 'int'>
print(type(num_float)) # <class 'float'>

print(7 // 2) # 3 (floor division)
print(7 ** 2) # 49 (power/exponent)
print(7 % 2) # 1 (modulus - remainder after division)
print(abs(-4)) # 4 (absolute value)

print(round(5.75)) # 6
print(round(5.75, 1)) # 5.8

print('Convert to a number (Casting to a number):')
print(int('77')) # 77 as a number

Leave a Reply

Your email address will not be published. Required fields are marked *