我有两个函数,一个用于清除输入文本,另一个用于测试清除文本是否为十六进制。当向cleaner函数传递一个包含所有空格的字符串时,它会去掉这些空格,留下一个空字符串。你知道吗
我不明白为什么字符串.十六进制数字()不会在这个空字符串上呕吐,让它作为有效的十六进制传递。你知道吗
def testHex(ciphertext):
cleancipher = cleanHex(ciphertext)
if all(h in string.hexdigits for h in cleancipher):
print('String is valid hex.')
else:
print('String is not valid hex.')
def cleanHex(ciphertext):
return(ciphertext.replace(' ', '').replace('0x', '').replace(':', '').replace('\\x', '').strip())
testHex
为空字符串输出String is valid hex.
,因为all
为空iterables返回True
它是documented
相关问题 更多 >
编程相关推荐