Using loops within functions:
Using loops within functions
suggest changeIn Python function will be returned as soon as execution hits “return” statement.
In this example, function will return as soon as value var has 1
def func(params):
for value in params:
print ('Got value {}'.format(value))
if value == 1:
# Returns from function as soon as value is 1
print (">>>> Got 1")
return
print ("Still looping")
return "Couldn't find 1"
func([5, 3, 1, 2, 8, 9])
output
Got value 5
Still looping
Got value 3
Still looping
Got value 1
>>>> Got 1
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents
3List
22Reduce
27Classes
28Counting
31Set
42Tuple
45Enum
60setup.py
62Sockets
89urllib
92Idioms
104Stack
105Profiling
109Logging
111os module
118Mixins
120ArcPy
123Websockets
126Arrays
128Polymorphism
1322to3 tool
135Unicode
138Neo4j
140Curses
141Templates
145heapq
146tkinter
154Audio
155pyglet
156queue module
157ijson
160Flask
161Groupby
163pygame
165hashlib
166Gzip
167ctypes
170configparser
179sys module
185pyaudio
186shelve
190Using loops within functions
191Contributors