python_while true
while true的實現
標準格式
while True:
try:
except:
例項,下面有兩個例子,分別是引入while true,使得在輸入錯誤的情況下繼續輸入和終止
例子1
kk = {
'200':'OK',
'202':'Accepted',
'400':'Bad Request',
'403':'Forbidden',
'404':'Not Found',
'500':'Internal Server Error',
'502':'Bad Gateway'
}
while True:
try:
message = input()
ans = kk[message]
print(ans)
except:
continue
此時結果為:
例子2
kk = {
'200':'OK',
'202':'Accepted',
'400':'Bad Request',
'403':'Forbidden',
'404':'Not Found',
'500':'Internal Server Error',
'502':'Bad Gateway'
}
while True:
try:
message = input()
ans = kk[message]
print(ans)
except:
break
此時結果為:
相關文章
- true || false && falseFalse
- null >=0 ? true:falseNullFalse
- WPF ClipToBounds True or falseFalse
- 使用 "switch(true)" 代替大量if
- 為什麼 [] == ![] 為 true?
- Go語言中fmt.Println(true)的結果一定是true麼?Go
- Python解惑:True與FalsePythonFalse
- Ruby中的true和falseFalse
- for(;;)和while(true)的區別While
- Flask debug=True 無效Flask
- 面試官:x !== x 可以為 true ?面試
- jsp: isErrorPage="true"的作用JSError
- div contenteditable="true" 新增placehoder效果
- (排坑) Cannot create property 'key' on boolean 'true'Boolean
- js判斷true和false一覽JSFalse
- Java之for(;;)和while(true)的區別JavaWhile
- java死迴圈while(true)vsfor(;;)JavaWhile
- ajax的true非同步或者false同步非同步False
- php true false isset empty is_null array()PHPFalseNull
- do_while_true退役讀後感While
- 讀 do_while_true 退役記有感While
- checked屬性值是true還是checked
- 在Lombok的加持下,“小狗”.equals(“老狗”) = trueLombok
- This fact remains true in NBA 2K22REMAI
- JavaScript:(a==1 && a==2 && a==3)能輸出true麼?JavaScript
- 資源相互引用時 需新增 PerformSubstitution=TrueORM
- dbms_session.set_close_cached_open_cursors(true)Session
- aria-hidden="true"有什麼用
- js中return、return true、return false的區別JSFalse
- 做「容量預估」可沒有true和falseFalse
- Android屬性設定android:noHistory="true"Android
- Spring 定義:abstract="true" ,可適用模板Spring
- True Session Wait Activity in Oracle 10g[zt]SessionAIOracle 10g
- WPF Slider Show integral value TickFrequency="1" IsSnapToTickEnabled="True"IDEAPT
- 題解:CF2030C A TRUE BattleBAT
- PaddleSeg2.8訓練驗證時報錯[Hint: Expected axis >= -rank && axis < rank == true, but received axis >= -rank && axis < rank:0 != true:1.]
- 【JavaScript】奇怪的知識void 0 === undefined 為 trueJavaScriptUndefined
- My Resignation--it is my true resignation letter