私はpythonの料理本を勉強しています。 私は以下のコードを実行しようとしています。これは、Pythonのクックブックの第8章にあります。 このコードは、クラスを行った後、クラスPythonのクラスのプロパティを作る
class Person:
def __init__(self, first_name):
self.first_name=first_name
#getter function
#property
def first_name(self):
return self._first_name
#settier function
def first_name(self, value):
print(value, isinstance (value,str))
if not isinstance(value, str):
raise TypeError("expected a string")
self._first_name=value
#deleter function
def first_name(self):
raise AttributeError("can not delete attribute")
c=Person('PETTER')
c.first_name(42)
の性質についてですが、私はインスタンスを作って、私は意図的に誤った値を入力します。
私はTypeError(文字列が必要です)を取得すると予想しました。 しかし、私はしませんでした。 私のコードのどの部分を変更する必要がありますか?
の詳細について@propertyと
@setter財産exapmle
を飾る機能が欠落していますトピックをオフトピックbとして閉じます。事実SOはSolveMyExerciseForMe.comではありません –