0

初心者の質問については申し訳ありませんが、プログラミングはかなり新しいです。私の質問は、親クラスから必要以上の属性を継承する場合、それらの属性の1つを別の属性と等しく設定するにはどうすればよいですか?ここに例があります:

class numbers():
     def __init__(self, x, y, z):
     # x, y and z initialized here

class new_numbers(numbers):
     def __init__(self, x, y):
        numbers.__init__(self, x, y=x, z)
        # what im trying to do is get the y attribute in the subclass to be equal to the x attribute, so that when the user is prompted, they enter the x and z values only.

ご協力いただきありがとうございます!

4

2 に答える 2

2

次のようなものが必要です。

class numbers(object):
    def __init__(self,x,y,z):
        # numbers initialisation code

class new_numbers(numbers):
    def __init__(self,x,z):
        super(new_numbers,self).__init__(x,x,z)
        # new_numbers initialisation code (if any)
于 2013-01-29T23:51:35.720 に答える
0

このようなことを意味していましたか?

class numbers():
     def __init__(self, x, y, z):
         # x, y and z initialized here

class new_numbers(numbers):
     def __init__(self, x, z):
        numbers.__init__(self, x, x, z)

関数/メソッド呼び出しでキーワードの後に​​非キーワード引数を使用することはできません。

于 2013-01-29T23:54:14.517 に答える