[英]confused about this error in printing array in python?
考慮下面的代碼; 我想從控制台屏幕的開頭打印數組Ptimes 3個空格。 我努力了
print " %s" %(Ptimes)
當我使用此表格沒有打印任何內容時,它表示存在錯誤“所有爭論都歸因於字符串格式過多。
原始的工作代碼是:
PN = input(" Enter each process time following by its arrival time separated by comma: ")
Ptimes = PN[::2]
Atimes = PN[1::2]
print Ptimes
print Atimes
Ptimes
是一個元組,和Python要查找每個 *元素的占位符Ptimes
。 將其包裝在元組中(添加逗號):
print " %s" % (Ptimes,)
演示:
>>> Ptimes = ('foo', 'bar')
>>> print " %s" % (Ptimes)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
>>> print " %s" % (Ptimes,)
('foo', 'bar')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.