python

python如何实现函数多态性

九三
215
2021-02-25 18:16:19
栏目: 编程语言

python如何实现函数多态性

在python实现函数的多态性,具体方法如下:

def remove_user(self,user_or_username):

try:

#If user_or_username is a User object

username = user_or_username.name

except AttributeError: #Oops -- didn't works. ask forgiveness ;-)

#If user_or_username is a string

username = user_or_username

remote.remove(username)

0
看了该问题的人还看了