当且仅当pass语句是该缩进块中的最后一条语句时,Spyder才会忽略pass
语句的缩进。
调试以下内容将直接跳转到调试点#2,而忽略#1 。它根本不应该输入else。调试时有点烦人。
它不会打印“ What ?!”。 (phe!)
for j in range(10): #j = 0, never enters any higher number
k=0
for i in range(5): #i goes up to i = 2
while i==2: #then enters here
k+=1 #k increases to 3
if k>2:
break #then when k is 3 this breaks the while
if k>2:
break #this breaks the for after the while broke
else: # anything inside this shouldnt be executed because the for was broken
pass #add a debug point (#1) here
print('What?!')
pass #and another debug point (#2) here
是每个设计还是一个错误?如果可以,为什么?
在这种情况下不会发生:
for j in range(10):
k=0
for i in range(5):
while i==2:
k+=1
if k>2:
break
if k>2:
break
else:
pass
print('What?!')
pass #debug point
continue
但是在这种情况下:
for j in range(10):
k=0
for i in range(5):
while i==2:
k+=1
if k>2:
break
if k>2:
break
else:
pass
print('What?!')
pass #debug point
pass
版本:
Spyder 3.3.1
Python 3.6.6 64位
QT 5.9.3
PyQT5 5.9.2
在Windows上。