我试图创建一种校对命令控制台输入的方法,并检查以确保该字符串是一个rgb十六进制字符串.(例如:#FAF0E6)目前我正在尝试:除了:阻止.
def isbgcolor(bgcolor):
#checks to see if bgcolor is binary
try:
float(bgcolor)
return True
except ValueError:
return False
Run Code Online (Sandbox Code Playgroud)
我也试过使用.startswith('#').我已经看到了如何用Java编写这个函数的例子,但我仍然是初学者和Python我所知道的.救命?