Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4533784
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:11:57+00:00 2026-05-21T14:11:57+00:00

Suppose I have s class, that has members op , left , right (this

  • 0

Suppose I have s class, that has members op, left, right (this is related question to How to assign an operation like sum or substitute, etc., to a variable ). So, in op I store an operator, for example – operator.add, operator.radd, etc. But I want to store operator.rfloordiv and there’s no such member in this class? :\ But I can overload __rfloordiv__, so it does exist at all.

The idea is to apply op to left and right when needed.

My approach is as follows: store some special string in my op and then, before applying op, to check if op is string. If so, write an ugly if-else statement, to check for all – rfloordiv, rmod, rtruediv. If not – just apply op with both parameters. But this is damn ugly..

Is there a better way to achieve this?

I know that this could be done with lambda function, but if I do it like this, is there any way to see what is this lambda function (for the moment, when I need to see what is op, I check it in an if statement like this: if self.op is operator.radd: .., but what if op is lambda function ? )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:11:58+00:00Added an answer on May 21, 2026 at 2:11 pm

    Most magic operator methods come in two flavours: the plain variant and the variant prefixed with r (example __add__() and __radd()__). If you try to add the objects a of type A and b of type B, Python first calls A.__add__(a, b). If this returns the special value NotImplemented, B.__radd__(b, a) is called.

    Both those magic methods corresond to operator.add in the operator module. Similarly, the magic methods __floordiv__() and __rfloordiv__() correspond to operator.floordiv.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that I have a Java class with a static method, like so: class
Suppose that we have a class called class1. The class1 has a method called
So suppose I have a tree class like this in c++ class Node{ void
I have a class that contains a member object. I would like to call
Suppose I have a class Base which has a member variable A* my_hash. I
I have a Node class that has an 'element' slot which contains a list
Suppose I have a class module clsMyClass with an object as a member variable.
Suppose I have a class with some attributes. How is it best (in the
Suppose I have a class 'Application'. In order to be initialised it takes certain
Suppose I have a class public class MyClass { private Set<String> set = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.