(小白)python 为什么用return会报错啊?
巴扎黑
巴扎黑 2017-04-18 10:26:44
0
3
527
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
巴扎黑
巴扎黑

reply all(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 needs to be used inside a function

Ty80

return can generally only be used in functions.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!