Python- Operators-6(a)



Python Operator



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:

  • 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*
*- These operators will be covered at a later stage when the related concepts are dealt.



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 −

OperatorDescriptionExample
+ AdditionAdds values on either side of the operator.a + b = 30
- SubtractionSubtracts right hand operand from left hand operand.a – b = -10
* MultiplicationMultiplies values on either side of the operatora * b = 200
/ DivisionDivides left hand operand by right hand operandb / a = 2
% ModulusDivides left hand operand by right hand operand and returns remainderb % a = 0
** ExponentPerforms exponential (power) calculation on operatorsa**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


Comments

  1. Good morning boys. Today's session is extremely important. Most of our classes will be based on the use of the OPerators.
    Pls go slow and try and understand the purpose , working and syntax of the operators.

    I am with you for any queries.

    ReplyDelete
  2. Mam do we have to note down all things in our registers
    -Ashish

    ReplyDelete
  3. Replies
    1. Good morning. Why arent you joining the zoom based classes?

      Delete
    2. Ma'am there was network issue. From today I will join

      Delete
  4. All are requested to first understand and then note down everything very clearly.\exactly as it appears on the screen

    ReplyDelete
  5. Replies
    1. Good morning. Why arent you joining the zoom based classes?

      Delete
  6. All to note that Practical part of Python will be covered on zoom. Pls be present in the class

    ReplyDelete
  7. Zoom can be easily installed on the mobile phone. Its NOT TOUGH. Dont be scared.
    Also dont forget we are in class X, we will have no time for basics once we return to school.

    ReplyDelete
  8. All queries to be shared on the group. This is tough concept. will cover this in the evening also

    ReplyDelete
  9. maam what is the meaning of operands

    ReplyDelete
  10. take for example-
    a+b
    In this expression, the identifiers a and b are operands while + is the operator

    ReplyDelete
  11. Ma'am what is python operator
    Precedence

    ReplyDelete
  12. As BODMAS rule exists for maths, where in an expression, the sequence of execution will be:
    Bracket Open Division Multiplication Addition Subtraction
    similarly in python, there are rules to operator precedence

    ReplyDelete
  13. Those at the top will be executed first and those at the bottom will be executed last

    ReplyDelete

Post a Comment

Popular posts from this blog

HOLIDAY HW