-1
x = [1,2,3,4,5,6,7,8,9,0]
for element in x:
return element

gives IndentationError: expected an indented block

x = [1,2,3,4,5,6,7,8,9,0]
for element in x:
     return element

gives error>>> SyntaxError: 'return' outside function

2 Answers2

0

You need to define this in a function and call that function for the return value. Something like this -

x = [1,2,3,4,5,6,7,8,9,0]
def find_element():
for element in x:
     return element
a = find_element()
print (a)

Code - https://ide.geeksforgeeks.org/MGO9MBWFyz

geekanant
  • 41
  • 3
0

A return statement is used to end the execution of the function call:

x = [1,2,3,4,5,6,7,8,9,0]
def fun():
    for element in x:
         return element

You can also return multiple values from a function.

    return a,b,c
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Marwen Jaffel
  • 703
  • 1
  • 6
  • 14