我目前正在尝试学习python。我正在阅读 Al Sweigart 的Automate the Boring stuff with Python。在他的while循环示例中,他在循环中使用了not条件while(如下面的代码所示)。
name = ''
while not name != '':
print('Enter your name:')
name = input()
print('How many guests will you have?')
numOfGuests = int(input())
if numOfGuests !=0:
print('Be sure to have enough room for all your guests.')
print('Done')
这段代码工作正常。不过,我对这是如何工作的感到困惑。我们将 name 设置为''(空白值),然后在while循环中我们有while not name !=''. 为什么这不起作用while name != ''?