(小白)python 为什么用return会报错啊?
巴扎黑
巴扎黑 2017-04-18 10:26:44
0
3
532
try:
    r = requests.get('http://www.baidu.com',timeout=30)
    r.raise_for_status()
    r.encoding = r.apparent_encoding
    return r.text
except:
    return '我怎么知道又错了'
    
    
  SyntaxError: 'return' outside function
巴扎黑
巴扎黑

Antworte allen(3)
黄舟
import requests
try:
    r = requests.get('http://www.baidu.com',timeout=30)
    r.raise_for_status()
    r.encoding = r.apparent_encoding
except:
    print('我怎么知道又错了')
    
print(r.text)

return是在函数中返回



PHPzhong

return 需要在函数里面才能使用

Ty80

return 一般只能用在函数中。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!