2019-02-13
阅读量:
777
python如何设定返回值?
函数返回值可以为空,也可以设定特定返回值:
def hello_decorator(func):
def inner1(*args, **kwargs):
print("before Execution")
# getting the returned value
returned_value = func(*args, **kwargs)
print("after Execution")
# returning the value to the original frame
return returned_value
return inner1
# adding decorator to the function
@hello_decorator
def sum_two_numbers(a, b):
print("Inside the function")
return a + b
a, b = 1, 2
# getting the value through return of the function
print("Sum =", sum_two_numbers(a, b))
输出:
before Execution
Inside the function
after Execution
Sum = 3






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论