''' python中函数定义:函数是逻辑结构化和过程化的一种编程方法 python中函数定义方法: def test(x): "The function definitions" x += 1 return x def:定义函数的关键字 test:函数名 ():内可定义形参 "":文档描述(非必要,但是强烈建议为你的函数添加描述) x+=1:泛指代码块或程序处理逻辑 return:定义返回值 调用运行:可以带参数也可以不带 函数名() ''' def test(x): "计算一个数学函数" y = 2*x + 1 return y z = test(1) print(z) '''函数返回值''' #过程:就是没有返回值的函数 def test01(): "这是函数描述" msg = 'hello The little green frog' print(msg) def test02(): "这是函数描述" msg = 'hello WuDaLang' print(msg) return msg def test03(): "这是函数描述" msg = 'test03' print(msg) return 1, '2', ['3', 4], (5, '6'), {'7':'8'} t1 = test01() t2 = test02() t3 = test03() print('from test01 return is %s' % t1) print('from test02 return is %s' % t2) print('from test03 return is {}, {}, {}, {}, {}'.format(*t3)) #总结:返回值=0,返回None;返回值=1,返回object;返回值>1,返回tuple;