Linux 拨号vps windows公众号手机端

python如何实现函数多态性

lewis 6年前 (2019-03-16) 阅读数 8 #程序编程
文章标签 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)

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门