How to fix Python ValueError: unsupported format character ' ' (0x20) at index 3
Problem:
You are trying to use Python format strings like
format_string_example.py
"Hello %.3 world" % 1.234but you see an error message like
valueerror_traceback.txt
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-7cbe94e4525d> in <module>
----> 1 "Hello %.3 world" % 1.234
ValueError: unsupported format character ' ' (0x20) at index 9Solution
Your format string %.3 is incomplete ! You need to specify the type of value to format, e.g. f for floating point, d for integers, s for strings etc. So instead of %.3, write %.3f, or instead of just % write e.g. %f, %d or %s depending on the data type of the variable you want to insert there.
Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow