Python Basic Tutorial Notes--6th: Abstraction (function)

Source: Internet
Author: User

(1) Calculate the Fibonacci sequence:

1 fbis=[0,1]2 num=int (Input ("pleaseinputthe number")  3 for in range (Num-2):4     fbis.append (fbis[-2]+fbis[-1 ])5print(fbis)      

6.3 Creating a function

Callable (): function can determine whether a function can be called

The simplest example:

1 def Hello (name): 2     return " Hello "+name+"is youOK? "

Number of inputs, function of output Fibonacci sequence

1 deffbis (num):2     ifnum<=0:3         return "Input Error"4     ifNum==1:5         return[0]6     ifnum==2:7         return[0,1]8f=[0,1]9      forIinchRange (num-2):TenF.append (f[-1]+f[-2]) One     returnF

Record function: Write a description of the document and view the function's documentation

1 defHello (name):2     'This is a print function'#function Description Document as String3     Print("Hello"+name)4 5 #View function Documents7>>> Hello.__doc__8 'This is a print function'

6.4 Function parameters

The parameters of the function are the same as the c,c++ values are passed

Python Basic Tutorial Notes--6th: Abstraction (function)

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.