0% found this document useful (0 votes)
6 views1 page

Python - Simple Operators

The document explains the importance of operators in programming, highlighting basic operations like addition, subtraction, multiplication, and division. It also introduces more complex operators such as modulo and exponent, as well as bit operators for binary logic. Additionally, it briefly covers binary numbers and comparative operators used in conditional statements.

Uploaded by

mickey
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Python - Simple Operators

The document explains the importance of operators in programming, highlighting basic operations like addition, subtraction, multiplication, and division. It also introduces more complex operators such as modulo and exponent, as well as bit operators for binary logic. Additionally, it briefly covers binary numbers and comparative operators used in conditional statements.

Uploaded by

mickey
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Simple Operators
a. Variables are great but will be unchanging without operators. Just like simple
mathematics, there are some basic operations like addition, subtraction,
division, and multiplication. The operation is addition, and its operator is the plus
sign. You can easily use the common line as a calculator by inserting the line “8 +
2” and pressing enter. You do not need to save this to a variable, but the result
will not be available to use later. It is always best to have variables for numbers
because they are saved for later and can be quickly changed in one place. That
way, if you no longer like the number 8 and want to replace it with 5, it will only
need to be changed in one place and the rest of the program will use it the same
way. Some people may not know that there are actually many more types of
operations. More complex operators, such as modulo (%) and the exponent (**)
are used to get more efficiency in number crunching. If you want to get really far
down into the binary code, all those 1s and 0s floating around, you can use bit
operators to do logic. Here, you can access data at the bit level and do logical
operations like AND, OR, XOR, etc. They are not commonly used, and we’ll stay
away from those. While we are on the topic, I will quickly explain binary numbers
because that is always useful to know. Binary numbers are base 2. That means
that every place in a number can go 0 or 1 in each place. In standard (decimal,
base 10) numbering, numbers can go from 0 to 9 in each place (10 numbers). As
a quick example, lets take the number 10. In decimal, this means there is a 1 in
the tens place and 0 in the ones place. This gives the number a value of 10. In
binary, the number has a 1 in the second place and 0 in the first place giving it a
value of 2. As you go further out, the numbers are multiplied by 2 instead of 10.
Therefore, 1000 is equal to 8 and not 1000. Other operators include the ones
used for comparing. These are the things such as greater than, less than, equal
to, etc. These are used a lot in IF statements, which we’ll talk about in our next
section. You can see here as well that the comparative operators can work inline.
If you type 5<4 in the command line, it will give you false.
b. [Link]

You might also like