函数在不应该返回元组时返回元组

我正在使用 python 2.7,这是我所拥有的。

方法:

def get_phone(self):
    digits = filter(str.isdigit, str(self.phone))
    if re.match(r'(0|380)d{9}', digits):
        operator = digits[-9:-7]
        digits = digits[-7:]
        return "+380 ({}) {}".format(opeself.rator, digits)
    return None

现在,如果我像这样使用这种方法:

dictionary = {
    'phone': User.get_phone()
} 

输出是:

{'phone': '+380 (12) 1234567'}

但如果我像这样使用它:

dictionary['phone'] = User.get_phone(),
dictionary['phone'] = User.get_phone(),

输出变成一个元组:

{'phone': ('+380 (12) 1234567',)}

我究竟做错了什么?

回答

您在此处添加了一个逗号:

这把它变成了一个元组


以上是函数在不应该返回元组时返回元组的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>