Hi, I'm trying to use a for loop within my "with" and "as" statement. Here is my code:

with open("text.txt", "w") as my_file:
    crunch = ["w","a","f","f","q","l","e"]
    for x in crunch:
        if x == "q":
    return crunch

It keeps returning the same error:

  File "python", line 8
SyntaxError: 'return' outside function

Could someone please explain to me what is going wrong here?


You don't need to return, as you are just editing the variables value.

Return only goes in functions.