繁体   English   中英

SyntaxError: 'return' 外部函数(使用 jupyter notebook)

[英]SyntaxError: 'return' outside function(using jupyter notebook)

SyntaxError: 'return' 外部函数,有什么解决方案吗? 使用 jupyter 笔记本

string='"hello"'
for i in string:
    if i=='\"':
      d=string.replace("\"","")
      return d
    else:
      return string

return 语句必须在函数内部

例如:

def my_function():
    string='"hello"'
    for i in string:
        if i=='\"':
          d=string.replace("\"","")
          return d
        else:
          return string

这解决并解释了您的错误。 弗拉斯评论 说:

“您的代码没有意义 - 直接使用单行 string = string.replace(""","") – furas"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM