文章詳情頁(yè)
(小白)python 為什么用return會(huì)報(bào)錯(cuò)啊?
瀏覽:133日期:2022-08-26 18:26:18
問(wèn)題描述
try: r = requests.get(’http://www.baidu.com’,timeout=30) r.raise_for_status() r.encoding = r.apparent_encoding return r.textexcept: return ’我怎么知道又錯(cuò)了’ SyntaxError: ’return’ outside function
問(wèn)題解答
回答1:import requeststry: r = requests.get(’http://www.baidu.com’,timeout=30) r.raise_for_status() r.encoding = r.apparent_encodingexcept: print(’我怎么知道又錯(cuò)了’) print(r.text)return是在函數(shù)中返回回答2:
return 需要在函數(shù)里面才能使用
回答3:return 一般只能用在函數(shù)中。
相關(guān)文章:
1. javascript - 如何將一個(gè)div始終固定在某個(gè)位置;無(wú)論屏幕和分辨率怎么變化;div位置始終不變2. html - vue項(xiàng)目中用到了elementUI問(wèn)題3. javascript - 原生canvas中如何獲取到觸摸事件的canvas內(nèi)坐標(biāo)?4. javascript - vscode alt+shift+f 格式化js代碼,通不過(guò)eslint的代碼風(fēng)格檢查怎么辦。。。5. javascript - 求解答:實(shí)例對(duì)象調(diào)用constructor,此時(shí)constructor內(nèi)的this的指向?6. javascript - 有什么比較好的網(wǎng)頁(yè)版shell前端組件?7. java - 如何寫(xiě)一個(gè)intellij-idea插件,實(shí)現(xiàn)編譯時(shí)修改源代碼的目的8. javascript - [js]為什么畫(huà)布里不出現(xiàn)圖片呢?在線等9. java 中Long 類(lèi)型如何轉(zhuǎn)換成Double?10. html5 - 有可以一次性把所有 css外部樣式轉(zhuǎn)為html標(biāo)簽內(nèi)style=" "的方法嗎?
排行榜

熱門(mén)標(biāo)簽