- Iteration
What is an iteration? What's the difference between being recursive and recursion?
According to Wikipedia and online information:
Iterations: iterations are activities that repeat the feedback process and are often intended to close and reach the desired goal or result. Each repetition of the process is called an "iteration",
The result of each iteration is used as the initial value for the next iteration.
If the 1+2+3+4+5 and:
What about recursion? Refers to the method of using the function itself in the definition of a function. That is, the function keeps calling itself until a certain condition is met.
And how is recursion to seek 1--5?
Recursive and iterative implementations of the Fibonacci sequence:
1 deffib (n):2 ifN>0:3 if(n==1orn==2):4 return15 Else:6 returnFIB (n-1) +fib (n-2)7 Else:8 return-19 deffib_2 (n):Ten ifn<=0: One return-1 A Else: -A=1 -B=1 theS=1 - forIinchRange (n-2): -s=a+b -A=b +b=s - returns + PrintFIB (int (raw_input ('Please input a number from want to calculate the FIB number:'))) A Printfib_2 (int (raw_input ('Please input a number from want to calculate the FIB number:')))
- Which of the python is iterative?
The way in which objects are scanned from left to right is iterative .
How can you tell if an object is not iterative?
That's what StackOverflow said. Http://stackoverflow.com/questions/1952464/in-python-how-do-i-determine-if-an-object-is-iterable
- Using Python's built-in function, Hasattr, hasattr (object,name) Returns True when object has the Name property. The Iteration property is __iter__.
2. Use the iterable type of the collections module to determine
- For general iterative types, you can iterate over them with for-in
- But what about a dictionary with key-value pairs? For value values, the Itervalues () function is required to manipulate the value
1capitals={' China':'Beijing','America':'Washington','Russia':'Moscow'}2 Print 'countries:'3 forCountryinchCapitals:4 PrintCountry5 Print 'Capitals:'6 forCapitalinchcapitals.itervalues ():7 PrintCapital
You can see that when the dictionary iterates, the resulting values do not necessarily follow the order.
Python Learning Notes (iii)--Iteration