Python question when not str

Asked 2 years ago, Updated 2 years ago, 11 views

name = ''

while not name:                                                #### ➊
    print('Enter your name:')    
    name = input()

print('How many guests will you have?')
numOfGuests = int(input())

if numOfGuests:                                                #### ➋
    print('Be sure to have enough room for all your guests.')  #### ➌     

print('Done')

I heard that while not name is while not name!=" in this code, but while not name!=" Does this mean that name is not false? I'm so confused. Please explain what it means

python

2022-09-21 10:14

1 Answers

print(not '') # true
print(not None) # true

Repeat while if the conditional expression is true. not name is name == '' or name == None.

Therefore, while not name: means that if the value of name is evaluated as false, repeat the statement.


2022-09-21 10:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.