DEV Community

Cover image for Learn Python: Numbers
Rishi
Rishi

Posted on • Edited on

Learn Python: Numbers

Numbers

Integer

i_am_an_integer = 2020 
print(i_am_an_integer)
Enter fullscreen mode Exit fullscreen mode

Float

i_am_a_float = 20.123456  
print(i_am_a_float)
Enter fullscreen mode Exit fullscreen mode

Arthmetic Operations

maths_operation = 6 + 5 - 4 * 3 / 2
print(maths_operation)
Enter fullscreen mode Exit fullscreen mode

Division

Division always returns a float.

float_division = 48 / 2 
print(float_division);
Enter fullscreen mode Exit fullscreen mode


float_division2 = 49 / 3 
print(float_division2);
Enter fullscreen mode Exit fullscreen mode

Integer Division

To do integer division, we must use: //.

integer_division = 50 // 2 
print(integer_division);
Enter fullscreen mode Exit fullscreen mode


integer_division2 = 49 // 3 
print(integer_division2);
Enter fullscreen mode Exit fullscreen mode

Modulus | Remainder

remainder = 17 % 5;
print(remainder)
Enter fullscreen mode Exit fullscreen mode



Top comments (0)