Python Language Using loops within functions Return statement inside loop in a function

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


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

        print ("Still looping")

    return "Couldn't find 1"

func([5, 3, 1, 2, 8, 9])


Got value 5
Still looping
Got value 3
Still looping
Got value 1
>>>> Got 1

Got any Python Language Question?