(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)