[Tutor] Beginners question
Peter Otten
__peter__ at web.de
Tue Mar 31 07:50:35 EDT 2020
Alex Kleider wrote:
>
>>> while True:
>>> # get input
>>> # if input means quit
>>> break # break out of the loop
>>> # proceed with whatever you want to do
>>
>>
>> I am 'breaking rules'* here...
>>
>> The above always looks so untidy to my eye. Could we use the 'walrus
>> operator' instead of while True:?
>>
>> *
>> 1 I haven't loaded v3.8 at home, to be able to test for myself.
>> 2 'walrus' is likely beyond the OP's level of learning
>
> Agreed, and probably beyond mine as well but I for one would very much
> like to see how it could make this look less 'untidy.'
While I prefer the old-fashioned way here's how to spell the while loop
without break:
>>> while (word:=input("Enter a word: ")) != "quit":
... print(f"The word is {word!r}")
...
Enter a word: hello
The word is 'hello'
Enter a word: world
The word is 'world'
Enter a word: quit
>>>
> (Follow up question will be how to install p3.8: Ubuntu 18.4LTS,
> virtualenvwrapper:
> pip install python3.8 ... ????
> )
Dunno, I've always done the
$ ./configure
$ make
$ sudo make altinstall
dance. This should get you a python3.8 while not interfering with the system
pythons. You can then proceed to make a virtual environment with
$ python3.8 -m venv whatever
More information about the Tutor
mailing list