Python学习之路:函数介绍
生活随笔
收集整理的這篇文章主要介紹了
Python学习之路:函数介绍
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
編程:面向對象:華山派----->類---->class
? ? ? ? ?面向過程:少林派----->過程--->def ?一段段的函數和功能包含在過程中
? ? ? ? ?函數式編程:逍遙派--->函數---->def
? ? ? ? ?過程就是沒有return返回值的函數
函數的定義:數學函數的定義,兩個變量x和y,y=2x;
編程語言中函數的定義:函數是邏輯結構化和過程化的一種編程方法。
1 #定義函數 2 def test(x): 3 "The function definition" 4 x+=1 5 return x #函數的完整定義 6 7 def func1(): 8 "testing" 9 print("in the func1") 10 return 0 11 12 13 #定義過程 14 def func2(): 15 "testing" 16 print("in the func2") 17 18 #調用函數: 19 x=func1() 20 #調用過程 21 y=func2() 22 23 print('from func1 return is %s'%x) #返回0 24 print("from func2 %s"%y)#返回None?
函數式編程的優點:可擴展、保持一致性、代碼重用性
import timedef logger():time_format ='%Y-%m-%d %X'time_current =time.strftime(time_format)with open('a.txt','a+') as f:f.write('%s end action\n'%time_current)def test1():print('in the test1')logger()def test2():print('in the test2')logger()def test3():print('in the test3')logger()x=test1() y=test2() z=test3()?
轉載于:https://www.cnblogs.com/xiaobai005/p/7828814.html
總結
以上是生活随笔為你收集整理的Python学习之路:函数介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做梦梦到打老鼠是什么意思呢
- 下一篇: 【python】内存相关