Python Forum
???: if "{choice}" in self._command
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
???: if "{choice}" in self._command
#1
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
Reply
#2
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?
Reply
#3
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)
Reply
#4
Thanks for clearing up my confusion!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  combobox_callback(choice choice part of openfile name (kind of dependency) janeik 9 1,461 Sep-10-2023, 10:27 PM
Last Post: janeik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020