Home>Article>Backend Development> How to call class methods in python
Call of class method:
Similar to ordinary function call
1. Internal call of class: self.
2. Call outside the class:
Note: In the above two calling methods, self does not need to be included in the parameter list provided.
Demonstrate a class:
wash.py class Washer: def __init__(self): self.water = 0 self.scour = 0 def add_water(self,water): print('Add water:',water) self.water = water def add_scour(self,scour): self.scour = scour print('Add scour:',self.scour) def start_wash(self): print('Start wash...') if __name__ == '__main__': w = Washer() w.add_water(10) w.add_scour(2) w.start_wash()
Running results:
Learn in the Python tutorialcolumn!
The above is the detailed content of How to call class methods in python. For more information, please follow other related articles on the PHP Chinese website!