Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Operators Are Methods#

Sumit Rawal answered on May 23, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • What Does the // Operator Do?

  • Operators Are Methods#

    0

    In the previous lesson, you were introduced to methods. Operators are simply methods called using the operator notation we discussed in the previous lesson.

    Operators usually follow an infix notation. The infix notation is where the operator is situated between two operands. Operands are the data objects that the operator is performing an operation on.

    After the operator has performed its specific operation, the output is the result of the operation.

    What does this remind you of? A method. Where the operator is our function/method and the operand before the operator is the object the method acts upon. While the operand after the operator is the argument passed to the method.

    In Scala operators are not special language syntax; any method can be an operator. What makes a method an operator is how you use it. When we wrote string1.indexOf('W') in the previous lesson, indexOf was not an operator. But when we wrote string1 indexOf 'W', indexOf was an operator, because we’re using it in operator notation.

    In the previous lesson, we used the infix notation to call a method. In this lesson, let’s try to use an operator using the ordinary method call.

    Note: The infix notation is a much simpler syntax and is the conventional way of using operators.

    Popularity 1/10 Helpfulness 1/10 Language python
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 23 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.