Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Creating Methods in Python

class Parrot:
        # instance attributes
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    # instance method
    def sing(self, song):
        return "{} sings {}".format(self.name, song)

    def dance(self):
        return "{} is now dancing".format(self.name)

# instantiate the object
blu = Parrot("Blu", 10)

# call our instance methods
print(blu.sing("'Happy'"))
print(blu.dance())
Comment

PREVIOUS NEXT
Code Example
Python :: python asyncio.run() 
Python :: Max fonction code in python 
Python :: tuple in python 3 
Python :: python bubble 
Python :: length of list without len function 
Python :: join string with comma python 
Python :: python string to list of chars 
Python :: add two strings together 
Python :: concatenate list in python 
Python :: remove dups in list of tuples 
Python :: python check if string is url 
Python :: style django forms with crisp 
Python :: python catch any exception 
Python :: how to get data after last slash in python 
Python :: df set index 
Python :: sep and end in print python 
Python :: how to add one to a variable in python 
Python :: Requested runtime (python-3.7.5) is not available for this stack (heroku-20). 
Python :: python rock paper scissors game 
Python :: get schema of json pyspark 
Python :: print to screen 
Python :: python check date between two dates 
Python :: disable sns plot python 
Python :: every cell change comma to point pandas 
Python :: inherit functions from other classes 
Python :: multiple assessment in python 
Python :: decision tree best param 
Python :: gunicorn django static files 
Python :: Flatten List in Python Using NumPy concatenate 
Python :: alexa python get slot value 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =