Skip to main content

NUMBERS AND OPERATORS


NUMBERS AND OPERATORS

Numbers are normal operand values which are used to perform set of task or operations using an operator. Numbers can be integers, decimal value, etc.
There are many operators in Python. Some of them are listed below:

Ø Arithmetic operators
Ø Comparison operators
Ø Logical operators
Ø Bitwise operators
Ø Assignment operators

In this blog we will see about Arithmetic operators and understand how to use it with Python IDLE to perform certain calculations.

PYTHON ARITHMETIC OPERATORS
OPERATOR
DESCRIPTION
EXAMPLE
Addition (+)
Adds two values
5+6 = 11
Subtraction (-)
Subtracts
5-3 = 2
Multiplication (*)
Multiplies two values
4*8 = 32
Division (/)
Divide by right hand operand
6/3 = 2
Modulus (%)
Divides and gives the remainder
6%3 = 0
Exponential (**)
Performs power calculations on operand
2**4 = 32
Double slash (//)
Rounds the float to the nearest value integer.
Positive case: Round to positive existing integer
Negative case: Round towards negative infinity
13//2 = 6
-13//2 = -7

The priority or hierarchy of operators is defined using a standard rule of BODMAS which means Brackets, Division, Multiplication, Addition and Subtraction. In this priority a given equation with multiple operators can be solved.

Other operators will be explained in other blogs.


Comments

Popular posts from this blog

DECISION MAKING STATEMENTS

DECISION MAKING STATEMENTS During the execution of the program, when there is a specific application to check the condition and make a proper decision, Decision making statements are used to anticipate specific actions which has to be taken depending upon the condition. Decision making statements are evaluated using TRUE and FALSE values. For example, if a particular condition is TRUE what outcome is expected and when, FALSE what outcome is expected. Depending on the application of program, set of statements are written into the code to perform a particular task. Python provides following types of decision making statements: Ø If statement: It is normal If statement which has condition in terms of Boolean expression, comparison operators, etc. Ø If..else statement: In this case, an If is followed by an else statement. It means ‘IF’ condition turns to be FALSE than ‘ELSE’ will be executed automatically Ø Ladder If.. else if .. else if: This is an extension o...

WHILE LOOP IN PYTHON

WHILE LOOP IN PYTHON Loops are used to execute a piece of code or set of statements multiple times in a program as long as the condition is true. While loop is the basic loop structure in Python. Syntax: While (expression):             Statement(s) Here, condition may be any logical expression and statement(s) can be single statement or multiple statements. The loop will iterate or execute until the condition is true. When the condition becomes false, program comes out of the loop and remaining statements are executed. In Python language, during any of the decision making, control statements and looping indentation is very important because, it specifies the set of statements to be a part of single code or block. Since no brackets are used to specify the complete code with in, indentation is used. Flowchart: In While loop, the main important thing is the loop may never be executed if the condition is...

COMPARISON, LOGICAL, ASSIGNMENT AND BITWISE OPERATORS

COMPARISON, LOGICAL, ASSIGNMENT AND BITWISE OPERATORS In this blog we will see about Arithmetic operators and understand how to use it with Python IDLE to perform certain calculations. PYTHON COMPARISON OPERATORS OPERATOR DESCRIPTION EXAMPLE        == Checks whether LHS is equal to RHS, then the condition becomes true 10==10 is true        != Checks whether LHS is not equal to RHS, then the condition becomes true 2!=3 is true        > Checks whether LHS is greater than RHS, then the condition becomes true 6>3 is true        < Checks whether LHS is less than RHS, then the condition becomes true 6<10 is true        >= Checks whether LHS is gre...