Python 函数

函数返回多个返回值

def multiple_return_value():
    import datetime
    d = datetime.date.today()
    val_1 = '年份为:{}'.format(d.year)
    val_2 = '月份为:{}'.format(d.month)
    return val_1, val_2  # 只需在return关键字后跟多个值(依次用逗号分隔)


val = multiple_return_value();  # Python将返回值包装成元组
print(val)

padding_im, draw_img = val
print(padding_im)
print(draw_img)

output

('年份为:2023', '月份为:5')
年份为:2023
月份为:5
posted @ 2023-11-24 16:35  VipSoft  阅读(8)  评论(0编辑  收藏  举报