python - Why does checking an empty string against string.hexdigits() return valid? -


i have 2 functions, 1 cleans input text, , 1 tests if cleantext hexadecimal. when passing cleaner function string of spaces, strips spaces, leaving null string.

what don't why string.hexdigits() doesn't barf on null string, , let's pass through valid hex.

def testhex(ciphertext):     cleancipher = cleanhex(ciphertext)     if all(h in string.hexdigits h in cleancipher):         print('string valid hex.')     else:         print('string not valid hex.')  def cleanhex(ciphertext):     return(ciphertext.replace(' ', '').replace('0x', '').replace(':', '').replace('\\x', '').strip()) 

testhex outputs string valid hex. empty strings because all returns true empty iterables

it documented

all(iterable)

return true if elements of iterable true (or if iterable empty).


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -