2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

python、クラスについて

Posted at

Personのクラスについてメモ。

以下、Personクラスを作成してみる。

.py
class Person:
 
 #初期設定
 def __init__(self, name,company,age):#selfはとりあえず必要
   self.name = name
   self.company = company
   self.age = age

 def say_hello(self,name):#selfはとりあえず必要
   print("こんにちわ{}さん。私ば{}です。".format(name, self.name))

 def __call__(self, name):#selfはとりあえず必要
   print("こんにちわ{}さん。私ば{}です。".format(name, self.name))
 
-------------------------------------------------------
Suzuki = Person("鈴木","ABC商事",45)
Suzuki.name
#鈴木

Suzuki.say_hello("加藤")
#こんにち加藤さん。私ば鈴木です。

Suzuki("田中")
#こんにちわ田中さん。私ば鈴木です。
#call関数はSuzuki.__call__("田中")としなくて良い(これでも可能だが適切ではない)

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?