Skip to content

Latest commit

 

History

History
24 lines (21 loc) · 532 Bytes

methods.md

File metadata and controls

24 lines (21 loc) · 532 Bytes

Back

Methods


Methods are functions defined inside the body of a class. They are used to define the behaviors of an object.

Example:

# With parameters
def speak(self, sound):
        return "{} says {}".format(self.name, sound)
# Without parameters
def description(self):
        return "{} is {} years old".format(self.name, self.age)
# Call method without parameters
print(mikey.description()) 
# Call method with parameters
print(mikey.speak("Gruff Gruff"))