I am puzzled why I can assign/unpack the return of split()
to the
appropriate number of variables, but the same fails for use in a
print string using formatting directives.
例如,考虑到:
In [202]: s
Out[202]: here are 4 values
In [203]: s.split()
Out[203]: [ here , are , 4 , values ]
这项工程按预期进行:
In [204]: a, b, c, d = s.split()
In [205]: print %s %s %s %s % (a, b, c, d)
here are 4 values
但这失败了。
In [206]: print %s %s %s %s % (s.split())
I am not sure why? Shouldn t the return of split()
be
unpacked and be distributed over the expected arguments for the
formatting strings?
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
C:laDesktop<ipython-input-206-600f130ff0b2> in <module>()
----> 1 print %s %s %s %s % (s.split())
TypeError: not enough arguments for format string
“说明有足够的论据”。 我确实有名单上的项目数目。 由于某种原因,该清单是否没有包装,而是没有转让变数?
I came across this in attempting to answer this question writing column entry just one below another in python