Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Methods | OOP Concepts
In-Depth Python OOP

bookMethods

メニューを表示するにはスワイプしてください

Methods are actions or operations that can be performed on a particular object.
For example, if an airplane is an object, its methods might include takeoff, landing, moving, changing speed, steering, checking status, and so on. Methods help an object perform various tasks and interact with it in program code.

The methods of a class are functions designed to be used by instances. You can define a function within the class and utilize it with instances.

123456789
class Plane: name = "Unknown" def fly(self, distance): print(f"The plane {self.name} flew {distance} km") bon = Plane() bon.name = "Bon" bon.fly(56)
copy

Note

You can retrieve the instance attributes using the self parameter within methods.

The bon.fly(56) is equal to:

Plane.fly(bon, 56)

Where self is the bon instance and distance is 56.

question mark

What is a method?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  7

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  7
some-alt