解释这段代码以及“not name”与“not name!=''如何相同“numOfGuests!=“0”与“numOfGuests”相同

2024-04-24 15:52:27 发布

您现在位置:Python中文网/ 问答频道 /正文

This is the source site 我无法理解这段代码, “While not name:”指的是什么?如本文所述,它怎么可能与“not name!=”相同还有“客人”=“0”与“if numOfGuests:”相同: 你的帮助会很感激的

name = ''
while not name: #(1)
    print('Enter your name:')
    name = input()
print('How many guests will you have?')
numOfGuests = int(input())
if numOfGuests: #(2)
    print('Be sure to have enough room for all your guests.') #(3)
print('Done')

Tags: the代码namesourceinputyourifis
1条回答
网友
1楼 · 发布于 2024-04-24 15:52:27

在python中,null值表示False,非null值表示True;在这段代码中,当您没有设置名称时,name为False,在您设置name值后,not name=False,循环将开始,并跳出循环

相关问题 更多 >