

How to Convert an Integer and Float to String with the str() Function If you’re insistent on using the encoding and errors parameters, then the object to convert must be a bytes object: my_num = b'45'Ĭonverted_my_num = str(my_num, encoding='utf-8', errors='strict') You only need the number you want to convert: my_num = 45 In this case, you don’t need the encoding and errors at all. This error occurs because you’re using the encoding parameter without providing a bytes object.

TypeError: decoding to str: need a bytes-like object, int found If you run the code, you’ll get this error: converted_my_num = str(my_num, encoding='utf-8', errors='errors') You have to comma-separate each of the parameters in the str() function, and the values of both encoding and errors have to be in strings: str(object_to_convert, encoding='encoding', errors='errors')įirst, let’s see how to use all the parameters of the str() function: my_num = 45Ĭonverted_my_num = str(my_num, encoding='utf-8', errors='errors') The values you can use for this parameter include strict, ignore, replace, and others.

