Where?
Run Python program, error appears in this line return "Unknow Object of%s"% value
Why?
%s means the value variable is loaded as a string, but the value is a Python tuple, and the tuple in Python cannot be formatted directly with%s and%, the error
The same?
Format a string using format or Format_map instead of%
Error code
def use_type (value): if Type (value) = = Int: return "int" elif type (value) = = float: return "float" else: return "Unknow Object of%s"% valueif __name__ = = ' __main__ ': print (Use_type) # passed tuple parameter Print (Use_type ((1, 3))
Correcting code
def use_type (value): if Type (value) = = Int: return "int" elif type (value) = = float: return "float" else: # format return "Unknow Object of {value}". Format (Value=value) # Format_map Way # return "Unknow Object of {value} ". Format_map ({ # " value ": Value #}) If __name__ = = ' __main__ ': print (Use_type (10) # Pass-through tuple parameter print (Use_type ((1, 3)))
Python-typeerror:not all arguments converted during string formatting