Wednesday, May 18, 2016

How to use basic operators in Python



Basic operators in Python
This section explains a bit on how to use basic operators in Python.

Arithmetic OperatorsJust as any other programming languages, the addition, subtraction, multipliion, and division operators can be used with s.
= 1 + 2 * 3 / 4.0
Try to predict what the answer will be. Does python follow order of operations?
Another operator available is the modulo (%) operator, which returns the integer remainder of the division. dividend % divisor = remainder.
remainder = 11 % 3
Using two multipliion symbols makes a power relationship.
squared = 7 ** 2
cubed = 2 ** 3
Using Operators with StringsPython supports conenating strings using the addition operator:
helloworld = "hello" + " " + "world"
Python also supports multiplying strings to form a string with a repting sequence:lotsofhellos = "hello" * 10
Using Operators with Lists
Lists can be joined with the addition operators:
even_s = [2,4,6,8]
odd_s = [1,3,5,7]
all_s = odd_s + Even s.


No comments:

Post a Comment