For example:
strs=(1,2,3,4) #Create a collection
strs
(1, 2, 3,4)
>>> print 'strs= %s ' % strs
Traceback (most recent call last):
File "<pyshell#43>", line 1, in <module>
print 'strs= %s ' % str
TypeError: not all arguments converted during string formatting
Reason: the 1% operator can only be used directly for string (‘123 ‘). If it is a list ([1,2,3]) or tuple, it needs to match operators one by one.
To put it bluntly, it’s written in parentheses with commas (STRs,)
Solution:
print 'strs= %s' % (strs,)
strs= (1, 2, 3,4)
or
print 'strs= %s,%s,%s,%s' % sstr
strs= 1,2,3,4
# simple explanation
the% before and after explanation does not correspond to the number of parameters after explanation, such as
File "<pyshell#37>", line 1, in <module>
print '%f meters is the same as &f km' % (meters, kilometers)
TypeError: not all arguments converted during string formatting
There are two parameters of miles and kilometer in the back, only one% F in the front, and one & amp; with wrong print;, The former is inconsistent with the latter; If you change it to
print '%f miles is the same as %f km' % (miles, kilometers)
That’s all
Read More:
- [Solved] TypeError: not all arguments converted during string formatting
- Python Time Module timestamp, Time string formatting and Conversion (13-bit timestamp)
- Typeerror in Python regular expression: expected string or bytes like object
- In Java, int is converted to string, and zero is added before the number of bits is insufficient
- Python TypeError: coercing to Unicode: need string or buffer, NoneType found
- TypeError: int() can’t convert non-string with explicit base
- Grep finds all files containing a string in Linux
- Python time tuples are converted to timestamps, strings
- A repeated string is composed of two identical strings. For example, abcabc is a repeated string with length of 6, while abcba does not have a duplicate string. Given any string, please help Xiaoqiang find the longest repeated substring.
- [Solved] ValueError: only one element tensors can be converted to Python scalars
- Typeerror in Python: ‘nonetype’ object is not Iterable
- Python error: typeerror: ‘Int’ object is not subscribable
- python-TypeError: list indices must be integers, not tuple Solution
- Python reported error: typeerror:’int’object is not subscriptable
- Python about typeerror: required argument ‘mat’ (POS 2) not found error resolution
- Python error: typeerror: ‘module’ object is not callable
- Python error: typeerror: not supported between instances of ‘STR’ and ‘Int’
- [How to Solve] Python TypeError: ‘int‘ object is not subscriptable
- Python error prompt: typeerror: ‘builtin’_ function_ or_ method‘ object is not subscriptable
- Python ValueError: only 2 non-keyword arguments accepted