Python-函数

面向对象编程:华山派----------类  class

面向过程编程:少林派----------过程     def定义,没有返回值

函数式编程:峨眉派-------------函数     def定义,有返回值

在Python中,过程也被当作函数对待,返回值为null

 

  1:类似打印日志  

import time    ####导入time的时间包
time_format='%Y-%m-%d %X' ####定义时间类型
time_current=time.strftime(time_format) ####得到当前的时间
def printlog(): ###定义追加写日志的函数
with open("log.txt",'a+') as f :
f.write("%s end action\n" %time_current)
def test1():
print ("in the test1")
printlog()
def test2():
print ("in the test2")
printlog()
def test3():
print ("in the test3")
printlog()
test1()
test2()
test3()

     

 

posted on 2019-03-20 15:21  遇见阿杜  阅读(182)  评论(0编辑  收藏  举报