Python- Operators-6(a)
Good Morning Boys.
Lets take a look at the topic of the day "Python Operators"
-----------------------------------------------------------------
By the end of this session, you will be able to:
Operators are used to perform operations on variables and values.
By the end of this session, you will be able to:
- Identify the various operators available in Python
- understand and apply the various arithmetic operators in Python.
- Understand the working of the arithmetic operators (after the discussion on the ZOOM class)
Operators are used to perform operations on variables and values.
Python divides the operators in the following
groups:
- Arithmetic
operators
- Assignment
operators
- Comparison
operators
- Logical
operators
- Identity
operators*
- Membership
operators*
- Bitwise operators*
Python Arithmetic Operators
Arithmetic operators are used with numeric
values to perform common mathematical operations. Assume variable a holds 10 and variable b holds 20, then −
| Operator | Description | Example |
|---|---|---|
| + Addition | Adds values on either side of the operator. | a + b = 30 |
| - Subtraction | Subtracts right hand operand from left hand operand. | a – b = -10 |
| * Multiplication | Multiplies values on either side of the operator | a * b = 200 |
| / Division | Divides left hand operand by right hand operand | b / a = 2 |
| % Modulus | Divides left hand operand by right hand operand and returns remainder | b % a = 0 |
| ** Exponent | Performs exponential (power) calculation on operators | a**b =10 to the power 20 |
| // | Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (towards negative infinity) − |
Let us focus on the following example ( Note the output. If you dont understand, share your doubts in the comment section.)
Example #1: Arithmetic operators in Python
x = 15
y = 4
# Output: x + y = 19
print('x + y =',x+y)
# Output: x - y = 11
print('x - y =',x-y)
# Output: x * y = 60
print('x * y =',x*y)
# Output: x / y = 3.75
print('x / y =',x/y)
# Output: x // y = 3
print('x // y =',x//y)
# Output: x ** y = 50625
print('x ** y =',x**y)
When you run the program, the output will be:
x + y = 19 x - y = 11 x * y = 60 x / y = 3.75 x // y = 3 x ** y = 50625
good morning ma'am
ReplyDelete-Artham
good morning ma'am
ReplyDelete-Ashish
Good morning boys. Today's session is extremely important. Most of our classes will be based on the use of the OPerators.
ReplyDeletePls go slow and try and understand the purpose , working and syntax of the operators.
I am with you for any queries.
Mam do we have to note down all things in our registers
ReplyDelete-Ashish
Yes dear
DeleteGood morning ma'am
ReplyDelete- rahul
Good morning. Why arent you joining the zoom based classes?
DeleteMa'am there was network issue. From today I will join
Deletegood morning maam
ReplyDeleteClement
All are requested to first understand and then note down everything very clearly.\exactly as it appears on the screen
ReplyDeleteGood morning ma'am
ReplyDelete-Geet
Good morning ma'am
ReplyDeleteKrish
Good morning. Why arent you joining the zoom based classes?
DeleteAll to note that Practical part of Python will be covered on zoom. Pls be present in the class
ReplyDeleteZoom can be easily installed on the mobile phone. Its NOT TOUGH. Dont be scared.
ReplyDeleteAlso dont forget we are in class X, we will have no time for basics once we return to school.
Good morning ma'am
ReplyDeleteAll queries to be shared on the group. This is tough concept. will cover this in the evening also
ReplyDeleteOk ma'am
Deletemaam what is the meaning of operands
ReplyDeletetake for example-
ReplyDeletea+b
In this expression, the identifiers a and b are operands while + is the operator
GOOD MORNING MAM
ReplyDeleteAron good morning. You are again late
DeleteMa'am what is python operator
ReplyDeletePrecedence
As BODMAS rule exists for maths, where in an expression, the sequence of execution will be:
ReplyDeleteBracket Open Division Multiplication Addition Subtraction
similarly in python, there are rules to operator precedence
Those at the top will be executed first and those at the bottom will be executed last
ReplyDelete