image
image
image

Chapter 9: Operators Inside the Python Language

image

Inside of Python, it is common to run into operators that will help to make your code a bit stronger. There are many types of operators and they are responsible for helping you to do things such as mathematical equations, comparing different parts of the code, and even giving a value over to the variable. There are many of these that you are able to work with depending on what the code is trying to do so let’s take a look at some of the operator types that you could use and see how they would work for you!

Arithmetic operators

The first type of operator that we will discuss is the arithmetic operator. These are the ones that would be able to help you do a mathematical equation, even soemthing as simple as adding together two oeprands, inside of the code. Some of the options that you have with the arithmetic operators includes:

You are able to use more than one of these at a time inside a statement of your code if that is needed. For example, you could add together three or more numbers if you need to or you can add a few numbers and then subtract some others if it works for your code. The rule here is to remember that you need to multiply all the numbers first, then divide the ones that have this symbol before moving on to addition and subtraction in order to get the right answer.

Comparison operators

Another type of operator that you will be able to use is the comparison operator. This one is helpful if you would like to compare the two or more values, or even the statements, that are inside of your code. They are often used with Boolean expressions because they are going to return a true or false result; you will either have two numbers that are equal to each other or not equal to each other for example so this is a good way to figure this out. Some of the comparison operators that you may use in your coding include:

The Logical Operators

The logiacl operators are also going to work in order to help with evaluating the input that the user gives you with the conditions that you have set. There are three main logical operators that you may be interested in using including the not, and, as well as the or and we are going to talk about them below:

Assignment Operators

And finally, we will look at the basics of the assignment operator. This one is usually going to use up the equal (=) sign in order to assign some kind of value over to your variable. If you would like the variable to be equal to 100, that is how you would write it all out. At some point in the code writing process, you will need to include this in there to tell the compiler the value of the variable and the assignment operators are going to help to make this happen.

You can sometimes use this in order to assign more than one value to the same variable as long as you use the right signs. You would just need to use the same variable and make sur eto bring in the right assignment operator, and then the variable can hold on to as many values as you would like.

Working with operators can make your code a bit easier to handle. You will be able to add together variables or do other mathematical equations. You will be able to assign a value to your variables to help the compiler know what you are doing, and you will even be able to do some comparisons to help figure out how the system is supposed to work in your program. Take some time to write out a few codes that use these operators and see just how simple it can be!