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

  • Home
  • SEARCH
  • 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 8863537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:00:14+00:00 2026-06-14T16:00:14+00:00

I have some class: class RSA: CONST_MOD=2 def __init__(self): print created def fast_powering(self,number,power,mod): print

  • 0

I have some class:

class RSA:
 CONST_MOD=2
 def __init__(self):
  print "created"

 def fast_powering(self,number,power,mod):
  print "powering"

I want to instantiate it and call method fast_powering:

 def main():
  obj=RSA() # here instant of class is created 
  val=obj.fast_powering(10,2,obj.CONST_MOD)  #  and we call method of object
  print val

And it works fine!

But I found that I can do it a little bit different way too, like:

def main():
 obj=RSA #do we create a link to the class without creating of object , or what?
 val=obj().fast_powering(10,2,obj().CONST_MOD) # and here we do something like
          # calling of static method of class in C++ without class instantiation,
          #  or ?
 print val

Sorry, I think a little bit in C++ way, but anyway
to my great astonishment it works too!
What’s actually happening here? Which wayn is more preffered? It’s some misterious for me.

Thanks in advance for any replies!

  • 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-06-14T16:00:16+00:00Added an answer on June 14, 2026 at 4:00 pm

    In your example, you’re doing:

    obj = RSA
    

    which is just binding the name obj to whatever was bound to RSA, which is the class RSA in your instance. Then you’re doing:

    obj().fast_powering(…)
    

    Which is equivalent to creating an instance of RSA and calling the method fast_powering on it. Note that this way, you’ll get a new instance of RSA on each call, which is probably not what you want. You’ll also have noticed, that the __init__ method has been called in the line cited above. Also consider:

    >>> class RSA:
    ...   def __init__(self):
    ...     print("foo")
    ... 
    >>> obj = RSA
    >>> obj() is obj()
    foo
    foo
    False
    

    Here we see that the statement obj() is obj() in fact creates two objects, which are of course not identical. This is opposed to your first example, as demonstrated using:

    >>> class RSA:
    ...   def __init__(self):
    ...     print("foo")
    ... 
    >>> obj = RSA()
    foo
    >>> obj is obj
    True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some class that I created visually in Flash Professional CS5 by transferring
I have some class that I'm passing as a result of a service method,
I have some class SimpleButton . It is a Child of Button class. Button
Suppose I have some class which has a property actor_ of type Actor .
So I have some class starting with #include <wchar.h> #include <stdlib.h> and there is
Basically I have some class objects, each with three properties. Once one class object
the basic idea is that you have some class that has a reference type
In Python, say I have some class, Circle, that inherits from Shape. Shape needs
For example, I have some class hierarchy (possibly, with all kinds of inheritance -
I have some test class TestKlass = (function() { function TestKlass(value) { this.value =

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.