Python Forum

Full Version: ???: if "{choice}" in self._command
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What does this do?

if "{choice}" in self._command
Curly braces are for replacement fields in strings for the .format method (or so I thought).

So I don't understand what this code is doing.

self._command = "M876"
choice = "0"

Thanks for any/all help
The string isn't an f-string, so the test is for whether the literal string "{choice}" is in self._command. Since it isn't an f-string, the value of the variable choice is irrelevant. Did you try running a complete program with that code and appropriate values?
BaiYouLihg4 Wrote:What does this do?
It tests if self._command contains the literal string "{choice}". If the author intended a replacement of "{choice}" by "0", he should have used f"{choice}" (for python version >= 3.6)
Thanks for clearing up my confusion!