zoukankan      html  css  js  c++  java
  • 函数和函数式编程

    1、函数的定义

    面向过程,面向对象,函数式编程。这是编程的方法论。

    面向对象的独门秘技是类,class。面向过程的独门秘技是过程,def。函数式编程的独门秘技是函数,def。

    过程就是没有返回值的函数。但是在python中,过程会返回none.

     1 def func1():
     2     #testing1
     3     print("in the func1")
     4     return 0
     5 def func2():
     6     #testing2
     7     print ("in the func2")
     8 
     9 x=func1()
    10 y=func2()
    11 
    12 print ("from func1 return is %s" %x)
    13 print ("from func2 return is %s" %y)

    2、为什么要用函数?

    可扩展,保持一致性,代码重用。

     1 import time
     2 def logger():
     3     time_format="%Y-%m-%d %X"
     4     time_current=time.strftime(time_format)
     5     with open('a.txt','a+') as f:
     6         f.write("%s end action
    " %time_current)
     7 
     8 def test1():
     9     print("in the test1")
    10     logger()
    11 
    12 def test2():
    13     print("in the test2")
    14     logger()
    15 
    16 def test3():
    17     print("in the test3")
    18     logger()
    19 
    20 test1()
    21 test2()
    22 test3()
  • 相关阅读:
    网络通信
    jvm调优
    rokectMq
    mybatis属性类
    spring cloud feign
    spring cloud hystrix
    spring cloud ribbon
    mybatis(二)创建代理类执行sql
    内存操作函数
    堆空间的开辟与使用
  • 原文地址:https://www.cnblogs.com/lyzfp/p/12267288.html
Copyright © 2011-2022 走看看