class Test:
def generate_attachment(self, type, owner_id, media_id):
return type + str(owner_id) + '_' + str(media_id)
如何像lambda函数一样表示这个函数? 我需要标记“自我”吗?在lambda变量?
答案 0 :(得分:2)
不,你可以这样做:
my_lambda = lambda type, owner_id, media_id: type + str(owner_id) + '_' + str(media_id)
使用名为type
的参数是一个坏主意,因为Python中已经存在一个由该名称存在的函数并且您将其覆盖。