Bootstrap FreeKB - Python (Scripting) - Subtraction and Decrement
Python (Scripting) - Subtraction and Decrement

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 987ab0 in the box below so that we can be sure you are a human.