Basic operators in Python
This section explains a bit at how toward use basic operators in Python.
Arithmetic OperatorsJust as any other programming languages, the addition, subtraction, multiplication, furthermore division operators can be used with numbers.
number = 1 + 2 * 3 / 4.0
Try toward predict what the answer will be. Does python follow order regarding operations?
Another operator available is the modulo (%) operator, which returns the integer remainder regarding the division. dividend % divisor = remainder.
remainder = 11 % 3
Using two multiplication symbols makes a power relationship.
squared = 7 ** 2
cubed = 2 ** 3
Using Operators with Strings Python supports concatenating strings using the addition operator:
helloworld = "hello" + " " + "world"
Python also supports multiplying strings toward form a string with a repeating sequence:lotsofhellos = "hello" * 10
Using Operators with Lists
Lists can be joined with the addition operators:
even_numbers = [2,4,6,8]
odd_numbers = [1,3,5,7]
all_numbers = odd_numbers + Even Numbers.