Python function (not yet continued)

Source: Internet
Author: User

What is a function?
在程序中,函数就具备某一功能的工具事先将工具准备好即函数的定义遇到应用场景拿来就用即函数的调用所以务必记住:#函数的使用必须遵循先定义,后调用的原则拿来加()就能用
    • Benefits of using functions
      Reduce Code Redundancy
      Enhance the extensibility of the program
      The structure and readability functions of the enhanced program are divided into 2 types: 1 no parameter function
2 parameter function What is the return value?
返回值是一个函数的处理结果,如果我们需要在程序中拿到函数的处理结果做进一步的处理,则需要函数必须有返回值

The return value of the function is defined with return
The format is:
return value

注意:    1、return是一个函数结束的标志,函数内可以有多个return,        但只要执行一次,整个函数就会结束运行    2、return 的返回值无类型限制,即可以是任意数据类型    3、return 的返回值无个数限制,即可以用逗号分隔开多个任意类型的值        0个:返回None,ps:不写return默认会在函数的最后一行添加return None        1个:返回的值就是该值本身        多个:返回值是元组
    • Three ways to call a function
      def max2 (x, y):
      If x > Y:
      return x
      Else
      Return y
      Form one:
      Max2 (ON)

      Form two:
      RES=MAX2 (3000,2000) * 12
      Print (RES)

      Form three:
      Res=max2 (Max2 (1000,2000), 3000)
      Print (RES)

Python function (not yet continued)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.