私はいくつかのクラスを持っています:
class RSA:
CONST_MOD=2
def __init__(self):
print "created"
def fast_powering(self,number,power,mod):
print "powering"
それをインスタンス化し、メソッド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
そしてそれはうまくいきます!
しかし、次のように、少し異なる方法でも実行できることがわかりました。
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
申し訳ありませんが、C ++の方法で少し考えますが、とにかく私の驚いたことに、それも機能します!
ここで実際に何が起こっているのですか?どちらのウェンがより好まれますか?それは私にとっていくつかの不思議です。
返信ありがとうございます!