In Python, integer variables are used to store whole numbers, which can be positive or negative. Quotation marks should not be used while defining integers. Integer variables can be treated like numbers for all mathematical operations.
If you need to store decimal numbers in Python, you should use float variables as integer variables ignore the decimal part of a number. When you combine a float variable and an integer variable in a mathematical calculation, the resulting answer will always be a float. You can do several arithmetic operations with floats and integers. Let us see some common operations with floats and integers.
- Addition
- Subtraction
- Multiplication
- Division
- Modulus (Remainder)
Now that we know what Integers and Floats are, let us now understand the syntax for performing different Mathematical operations on them in our Program
1. Performing Addition of Integers and Floats
x = 1
y = 2
sum = x + y
2. Performing Subtraction of Integers and Floats
x = 1
y = 2
subtraction = x - y
3. Performing Multiplication of Integers and Floats
x = 1
y = 2
multiplication = x * y
4. Performing Division of Integers and Floats
x = 1
y = 2
division = x / y
5. Performing Modulus of Integers and Floats
x = 1
y = 2
modulus = x % y