Using not in Boolean while Loops
Let’s take a look at an example of using
not in a
while loop. Just like with
not when there is a condition you want to be
False for a loop to iterate, because writing a condition that should be
True would be more complicated.
00:20 Suppose you’re writing a game or some other type of interactive program, and you want to personalize the experience for the player by having them enter their name. You don’t want the game to continue until they’ve done that.
After the user types their name, the
.strip() method will remove any leading or trailing whitespace. So if they haven’t typed in anything meaningful, it will just return the empty string. Once the user types something other than blanks, the game will continue.
Become a Member to join the conversation.