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

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

post - imageshack API cURL -