PYTHON AS A CAL

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Dr.

Dang Tri Dung – 3I – CTD – UEH


OPERATOR NAME EXAMPLE

+ Addition x+y

▪ Arithmetic operators are used


- Subtraction x-y with numeric values to perform
common mathematical
operations:
* Multiplication x*y

/ Division x/y

% Modulus x%y

** Exponentiation x ** y

// Floor division x // y
Operator Example Same As

= x=5 x=5

+= x += 3 x=x+3

-= x -= 3 x=x-3

*= x *= 3 x=x*3

/= x /= 3 x=x/3

%= x %= 3 x=x%3

//= x //= 3 x = x // 3
Assignment operators are used
**= x **= 3 x = x ** 3 to assign values to variables:
Operator Name Example

== Equal x == y
▪ Comparison operators are used
!= Not equal x != y to compare two values:

> Greater than x>y

< Less than x<y

>= Greater than x >= y


or equal to

<= Less than or x <= y


equal to
Operator Description Example

and Returns True if both x < 5 and x < 10


statements are true

or Returns True if one of x < 5 or x < 4


the statements is
true

not Reverse the result, not(x < 5 and x < 10)


returns False if the
result is true Logical operators are used to
combine conditional
statements:
▪ https://www.w3schools.com/python/module_math.asp

You might also like