函数的返回值

# _*_ coding: utf-8 _*_

# return 值:

# 注意点:

# 1. 函数额返回值没有类型限制
# 2. 函数的返回值没有个数限制
# 2.1 返回多个值:多个返回值用逗号分隔开,返回的是元组形式
# def function():
# print('from function')
# return 1,2.1,'hello',[1,2,3],(2,3)
# res = function()
# print(res,type(res))
# #from function
# #(1, 2.1, 'hello', [1, 2, 3], (2, 3)) <class 'tuple'>

# 2.2 返回1个值:返回的就是该值本身
# def function1():
# return 123
# res = function1()
# print(res,type(res))
# #123 <class 'int'>

# 2.3 返回0个值或者干脆没有返回值
# return:None
# def function2():
# pass
# res = function2()
# print(res)
# # None
#
# def function3():
# return
# res = function3()
# print(res)
# #None

猜你喜欢

转载自www.cnblogs.com/OutOfControl/p/9703024.html