Python学习笔记:TypeError: not all arguments converted during string formatting
生活随笔
收集整理的這篇文章主要介紹了
Python学习笔记:TypeError: not all arguments converted during string formatting
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
前言
在學習python中難免犯下一些幼稚的錯誤,為了方便后來人的學習與自己的進步,整理了在學習過程中犯下的錯誤,寫下此篇文檔。
目錄
文章目錄
- 前言
- 目錄
- 問題
- 舉例
- 解決方法
- 補充
問題
TypeError: not all arguments converted during string formatting
舉例
例如:
strs=(1,2,3,4) #創(chuàng)建一個集合strs(1, 2, 3,4)>>> print 'strs= %s ' % strsTraceback (most recent call last):File "<pyshell#43>", line 1, in <module>print 'strs= %s ' % strTypeError: not all arguments converted during string formatting原因:1 % 操作符只能直接用于字符串(‘123’),列表([1,2,3])、元組,因此需要一一匹配操作符。
解決方法
print 'strs= %s' % (strs,) strs= (1, 2, 3,4) 也可以用: print 'strs= %s,%s,%s,%s' % sstr strs= 1,2,3,4#簡單解釋
說明前后%和后面的參數(shù)數(shù)量不對應,比如
后面有miles和kilometer兩個參數(shù),前面只有一個%f,還有一個打印錯的&, 前后不一致; 如果改成
print '%f miles is the same as %f km' % (miles, kilometers)就可以了
補充
如果還有不會的,可以關注下面的公眾號,博主會在24小時內(nèi)回復。
總結
以上是生活随笔為你收集整理的Python学习笔记:TypeError: not all arguments converted during string formatting的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue弹出层滑动禁止背景跟着滑动_vue
- 下一篇: linux 软件 tar deb rmp