close

[Solved] Python SyntaxError :’return’ outside function

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python SyntaxError :’return’ outside function in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python SyntaxError :’return’ outside function Error Occurs?

Today I get the following error Python SyntaxError :’return’ outside function in python.

How To Solve Python SyntaxError :’return’ outside function Error ?

  1. How To Solve Python SyntaxError :'return' outside function Error ?

    To Solve Python SyntaxError :'return' outside function Error Problems mixing tabs/blanks are easy to have since both characters are “invisible”.

  2. Python SyntaxError :'return' outside function

    To Solve Python SyntaxError :'return' outside function Error Problems mixing tabs/blanks are easy to have since both characters are “invisible”.

Solution 1


I would check my indentation, it looks off. Are you possibly mixing tabs and spaces? The PEP8 (Python Style Guide) recommends using 4 spaces only. Unlike other languages, whitepace makes a big difference in Python, so consistency is important.

The above also makes the following recommendation:

When invoking the Python command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!

In particular, your 2nd else seems to be off (probably should be indented), and this method def __div__(self, other): too (which I would think ought to be at the same level as your other defs – i.e., moved “out” rather than indented).

Problems mixing tabs/blanks are easy to have since both characters are “invisible”.

Solution 2

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read