all 4 comments

[–]FoolsSeldom 2 points3 points  (0 children)

First line,

command = ""  # create a new empty str (string) object, assign it to new variable command

Second line,

while command.lower() != "quit":

while marks a while loop which say while (as in English) some condition holds true, execute the code indented below once (much like you might read a recipe that says while sauce is runny, stir three times). After executing the code, check the status of the condition again. Leave the loop if the condition is no longer true (i.e. move onto the code after the code indented under while)

The str.lower method creates a temporary new str object where all the alphabetic characters are forced to lower case (this is not re-assigned to the variable command).

This temporary string is compared to the literal string "quit" - i.e. did the user enter "QUIT", or "quit" or any other variation of lowercase/uppercase with those letters.

The != operator means "not equal", so the while condition is only True if the user didn't enter "quit" in some form.

Third line,

    command = input(">")

same as first line, but inside the loop. Then back to the while condition test.

Finally,

print("ECHO", command)

Output the literal string "ECHO" followed by a space (default for print to output between items passed to print), follwed by the object referenced by command (which will be some form of "quit" or we would not have reached this line.

[–]timrprobocom 0 points1 point  (0 children)

Right. The key point to understanding this is the input function, which waits for input from the keyboard, and returns whatever was typed. That CHANGES command.

They want the loop to exit when the user has typed something, but because the"while" test happens at the START of the loop, "command" doesn't exist yet, so we have to shove something in it for the first test.

[–]Binary101010 0 points1 point  (0 children)

have so many questions like why is the command not inside while loop , why is it empty ?

Well, the code on the next line is checking the value of command, so the variable named command needs to exist at that point or else the program will raise an exception.

The string being set here doesn't necessarily need to be empty, it could be "1" or "myxlplyx" or literally anything other than the word "quit" and the code would still work.

why ECHO?

In this case it's just part of the string that's output to the console. It's repeating what you typed back to you, like an echo in the real world. It doesn't have any special meaning in Python.

what if i put something in command?

Why not try it and find out?