如何在 python 变量或字符串中使用文字 # 而不注释掉其余部分?

how can I use a literal # in a python variable or string without it commenting out the rest?

可能很简单,但我想发送一个 post,其中包含目标期望的颜色十六进制,但我无法在颜色键中设置该值,因为它会注释掉后面的所有内容。

您不能使用 # 作为 Python 变量名称的一部分(参见 identifiers and keywords),但您可以将 # 后跟颜色字符串中的代码并将其作为有效载荷的一部分发送给 POSTing:

var = '#42'