Python (Scripting) - Subtraction and Decrement

by
Jeremy Canfield |
Updated: November 06 2023
| Python (Scripting) articles
Here is the most basic example of how to subtract two numbers in Python.
#!/usr/bin/python
print(5 - 1)
It is much more common to store the result in a variable.
#!/usr/bin/python
result = (5 - 1)
print(result)
Which should return the following.
2
Decimal numbers
By default, decimal will be used.
#!/usr/bin/python
result = (5.7 - 1.3)
print(result)
Which should return the following.
4.4
Whole numbers
round can be used to round to whole numbers.
#!/usr/bin/python
result = round(5.7 - 1.3)
print(result)
Which should return the following.
4.0
Did you find this article helpful?
If so, consider buying me a coffee over at