Yeild not supporting

when i’m writing generator function then it show a SyntaxError that " ‘yield’ outside function "

def fib():
    prev , curr = 0 , 1
    while True:
        yield curr
        prev, curr = curr, prev + curr
gen= fib()
next(gen)

In case there is no indentation problem or spelling mistake then kindly share your code with me by saving it at - https://ide.codingblocks.com/
And then do share the link of the saved ide with me so I can look into your code for the problem.