# Author : XueFeng
"""
1. 面向对象 华山派 类 class
2. 面向过程 少林派 过程 def
3. 函数式编程 逍遥派 函数 def
"""
# 函数与过程的简单讲解
# 函数
def func1():
"""testing"""
print("In the func1")
return 0
# 过程
def func2():
"""testing2"""
print('in the func2')
x = func1()
func2()
print('from func1 return %s' % x)
print('from func2 return %s' % y)
# 函数调用的简单讲解
import time
def logger():
time_format = "%Y-%m-%d %X" # 时间格式 年-月-日 具体时间
current_time = time.strftime(time_format) #获取当前时间
with open('.//test1.txt', 'a+') as fp: #已追加写的方式打开文件
fp.write('%s end action\n' % current_time)
def test2():
print('in the test1')
logger() #调用函数
def test3():
print('in the test1')
logger()
def test4():
print('in the test1')
logger()
test2()
test3()
test4()
# 关于函数返回值的问题详解
def test_1():
print('In the test1')
def test_2():
print('In the test1')
return 0
def test_3():
print('In the test1')
return 1, 'hello', ['jim', 1], {'jim': 23}
x = test_1()
y = test_2()
z = test_3()
print(x)
print(y)
print(z)
python_趣味函数式编程
最新推荐文章于 2020-10-28 19:52:00 发布