python - try应该写在for里面还是外面
大家讲道理
大家讲道理 2017-04-18 10:19:43
0
4
1003

有个for循环,比方这样

for x in datal:
    print x[0][0]

这个x0可能越界,打算try一下,那么try是应该写在for里面还是外面?求大神赐教

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(4)
刘奇

An exception will occur when printing, so it should be inside

伊谢尔伦

Place it in different locations, the code logic is different, it depends on the specific needs

Put it inside the loop and when an exception occurs, if the catch exception does not continue to be thrown, the loop will continue
; If it is placed outside, the loop will be terminated at the location of the first exception

PHPzhong

Put it outside the loop, the performance will be better~

Peter_Zhu

You can put it anywhere, but it’s not recommended to put it outside and only try it once, and put it in a loop and try it n times.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template