Legacy - Basic Operators Workout
- 02:47
Learn how to execute the basic operators in PyCharm using the Python Console available in PyCharm.
Downloads
Basic Operators - Python Workout FilesTranscript
Let us now look at some examples of basic operators in PyCharm. We shall be using the Python console in PyCharm for this workout, mainly due to the simplicity of this workout. The basic mathematical operators such as addition, subtraction, multiplication and division that are used in the Python coding are the same as in any other calculator device. Let us now look at some examples of operators. Firstly, addition. In order to add two numbers in Python, we use the plus sign. So for example, if we want to add 234 with 456, and then press enter, it's going to return 690. Similarly, in order to subtract two numbers in Python, we use the minus sign. So in order to surprise save 456 by 234, we're going to get 222. For multiplying two numbers in Python, we use the star sign. So if you want to multiply two by three, and press Enter using the star sign, we're going to get a six. In order to divide two numbers in Python, we use the slash sign. So for example, if we want to divide 23 by three and press enter, we would get a 7.666 decimal value. And again, we use the slash sign to divide two numbers in Python. Now, two operators to focus on are the flow division and the exponent. The flow division is performed by the double slash sign and Python. What it does is to return the integer value of the number rather than rounding the number. Let us try this for the other example, if we try to divide 23 by three, it's going to return a seven. As you can see, it's not rounding the decimal value in the previous question, but rather is returning the integer part of the value. Now let us look how we calculate the exponent of a number in Python. Generally, in most of the other programming languages, we use the caret or the upper triangular side to calculate the exponent of a value. But in Python, we would rather use the double star sign, which calculates the exponent. For example, if we want the square to, we would say to double start to return it for similarly if you want to square 45 say it's gonna return 2025. Simple.