So I'm a total beginner when it comes to Python and the "not" operator is kinda confusing me. So i was watching a BroCode video and he wrote this code:
name = None
while not name:
name = input("Enter your name: ")
print("Hello, "+name)
My question is: Doesn't this mean; while name is not nothing, do this? Isn't "not" supposed to make things opposite? So by that logic this code is not supposed to work. The condition of the while loop is that the name needs to be something, but it's not, so why does it even execute?
I finally got it and maybe this will help someone else as well:
= Noneor= ""- it is considered False (or Falsey to be more precise).Whilemeans While True and works as long as chosen condition is True.While notbasically means While False and works as long as set condition is False.= Falseand say: as long as the name is False - do the loop. As soon as we add anything to the name through input - the name becomes True and the loop is ended.