Vous êtes sur la page 1sur 3

Python Basics 01

Table of Content
Python is very easy to use and it can be used for arithmetic operations. in this section lets
look how we can use python as a calculator. This section is described three sections.
Python Basics 01 :- Python Oprerators
Python Basics 02 :- Python Data types, Variables and other basics (This will be discussed in
next section)

Python Basics 01 :- Python Operators

An operator is a symbol that is used for calculations. In simple 3 + 5 3 and 5 are operands
and + is the operator.Python language supports following type of operators.
Arithmetic Operators

Comparision Operators

Logical (or Relational) Operators

Assignment Operators

Conditional (or ternary) Operators

Python Arithmetic Operators


Operator

Description

Example

Addition - Adds values on either side of the


operator

a + b will give 30

Subtraction - Subtracts right hand operand


from left hand operand

a - b will give -10

Multiplication - Multiplies values on either


side of the operator

a * b will give 200

Division - Divides left hand operand by right


b / a will give 2
hand operand

Modulus - Divides left hand operand by right


b % a will give 0
hand operand and returns remainder

**

Exponent - Performs exponential(power)


calculation on operators

a**b will give 10 to the power 20

Floor Division - The division of operands


where the result is the quotient in which the

9//2 is equal to 4 and 9.0//2.0 is equal to


4.0

//

digits after the decimal point are removed.


Now let's see some examples in python IDE. (click here to see how the python GUI is
opened)

Here after I will not put any screen shots of the GUI. I will put only the code as follows.
>>> 2 + 3
5
>>> 3 - 1
2
>>> 2 * 5
10

Python Comparison Operators


Operator

Description

Example

==

Checks if the value of two operands are


equal or not, if yes then condition becomes
true.

(a == b) is not true.

!=

Checks if the value of two operands are


equal or not, if values are not equal then

(a != b) is true.

condition becomes true.


<>

Checks if the value of two operands are


equal or not, if values are not equal then
condition becomes true.

(a <> b) is true. This is similar to !=


operator.

>

Checks if the value of left operand is


greater than the value of right operand, if
yes then condition becomes true.

(a > b) is not true.

<

Checks if the value of left operand is less


than the value of right operand, if yes then
condition becomes true.

(a < b) is true.

>=

Checks if the value of left operand is


greater than or equal to the value of right
operand, if yes then condition becomes
true.

(a >= b) is not true.

<=

Checks if the value of left operand is less


than or equal to the value of right operand,
if yes then condition becomes true.

(a <= b) is true.

To get an more idea please go to


http://www.tutorialspoint.com/python/python_basic_operators.htm

Vous aimerez peut-être aussi