[英]Python: SyntaxError 'return' outside function error
我的代码上出现SyntaxError 'return outside function'
错误。 在这方面,我将不胜感激,对此我将不胜感激。
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
注意缩进。
我认为您需要将“ if”语句缩进到与“”字符串相同的级别上。
您的文档字符串比if条件缩进得多。 docstrings是Python对象,因此是代码的一部分。 确保代码统一缩进。
SyntaxError:外部函数“ return”它的仅缩进错误会改变您的return语句,错误将会丢失
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.