Yozuru
Yozuru

Reputation: 51

Python: SyntaxError 'return' outside function error

I am getting a SyntaxError 'return outside function' error on my code. I would appreciate any help in regards to this as this is frustrating me to no end.

def temp( T, from_unit, to_unit ) : # Function for temperature
        """ Convert between Fahrenheit, Celsius, or Kelvin. Where from_unit and to_unit are temperature units, either 'F' (or 'f') 
        for Fahrenheit, or 'C' (or 'c') for Celsius, or 'K'(or 'k') for Kelvin; and T is a temperature number (of float) for the
        unit from_unit """

    if from_unit == to_unit:  
        return T

Upvotes: 1

Views: 16051

Answers (3)

khushbu
khushbu

Reputation: 164

SyntaxError: 'return' outside function Its just indentation error shift your return statement and error will be lost

Upvotes: 1

Ben Whaley
Ben Whaley

Reputation: 34416

Your docstring is indented further than the if conditional. docstrings are Python objects and as such are part of the code. Make sure the code is indented uniformly.

Upvotes: 2

GreenAsJade
GreenAsJade

Reputation: 14685

Be careful with indentation.

I think you need to have the "if" statement indented at the same level as the """ string.

Upvotes: 2

Related Questions