Python computer programming language is a very useful utility for those who know how to properly make use of it. Being very rich in features, this computer technology offers many builtin utilities which can be used to accomplish many different tasks, from simple to very advanced.
Been using the Python computer programming language for some time, I can truly say that it is very flexible. Through this article, you are going to learn how to make use of Python to perform some basic arithmetic operations.
Before going any further, make sure to open a new Python console on your own operating system. Once you have managed to do it, then run the following piece of Python code in the interactive shell, and see what happens.
What's the one thing every developer wants? More screens! Enhance your coding experience with an external monitor to increase screen real estate.
3 + 4
Once the above piece of Python code is executed on my interactive console, I get the following result.
7
As you can see from the above result, Python supports arithmetic operations by default.
Not only can one make use of the addition operator in Python like shown in the above example, but subtraction too. The piece of code shown below is an illustration of subtraction in the interactive console of the Python computer programming language.
3 - 4
Once the above piece of Python code is executed in the interactive shell, I get the following output.
-1
Other math operations supported by default in the Python computer programming language include multiplication and division. The syntax for performing such operations is very simple and easy to understand by anyone.
You can easily perform multiplication in the Python computer programming language by making use of the syntax as shown below.
a * b
For example, to find the production of numbers 7 and 8, one must run the piece of Python code which is shown below.
7 * 8
Once the above piece of Python code is executed in my interactive console, I get the the following output.
56
The division operation in Python can be easily accomplished by making use of the following syntax.
a/b
For example to divide 4 by 2, the following piece of Python code can be used.
4/2
Final thoughts
There are many practical cases in which one can utilize the Python computer programming language as a calculator. Since it supports the basic arithmetic operations by default, one can easily utilize Python as a calculator.