字符串格式化输出时,其中一种方法是这样的:

for value in ['A', 'B', 'C']:print('输出: %s' % value)

我这打印子进程运行状态时print()了列表中的几个字符串,但报错如下:

TypeError: not all arguments converted during string formatting

翻译为:不是所有的参数在字符串格式化期间转换,我屮艸芔茻,出错位置看了下,原来是%打错了,打成了$,开始不知道啥原因,这错误第一次见,把这个信息发出来给大家参考。这是个低级错误

补充:字符串输出的几种方式

  • 直接print()输出
print('str1', 'str2', 'str3', '...')
  • '%s' % value 占位符输出
# 1. 单个
>>> name = 'Jason'
>>> print('name: %s' % name)
name: Jason
# 2. 多个
>>> name1, name2 = 'Jason', 'Bob'
>>> print('name1: %s; name2: %s' % (name1, name2))
name1:, Jason; name2: Bob
# 也可以自定义输出顺序
>>> print('name1: %s; name2: %s' % (name2, name1))
name1: Bob; name2: Jason
  • 输出多个字符串变量时,%后的多个变量需要用小括号括起来,否则会报没有足够参数的错:

    TypeError: not enough arguments for format string
    
  • format()格式化输出

# 1. 单个
>>> '{}'.format('world')
'world'
# 2. 多个
>>> word1, word2 = 'hello', 'world'
>>> hello_world = '{}, {}'.format(word1, word2)
>>> hello_world
'hello, world'
# 指定位置输出
>>> hello_world = '{1}, {1}'.format(word1, word2)
>>> hello_world
'world, world'
  • 指定位置输出时所有{}内都必须带参数的下标,否则会 不能从手动字段编号转换为自动字段编号ValueError 错误:

    ValueError: cannot switch from manual field specification to automatic field numbering
    
  • 也必须要在下标范围内,否则会报超限的IndexError 错误:

    IndexError: Replacement index 2 out of range for positional args tuple
    

TypeError: not all arguments converted during string formatting相关推荐

  1. python TypeError: not all arguments converted during string formatting 解决

    例如: strs=(1,2,3,4) #创建一个集合strs(1, 2, 3,4)>>> print 'strs= %s ' % strsTraceback (most recent ...

  2. Python学习笔记:TypeError: not all arguments converted during string formatting

    前言 在学习python中难免犯下一些幼稚的错误,为了方便后来人的学习与自己的进步,整理了在学习过程中犯下的错误,写下此篇文档. 目录 文章目录 前言 目录 问题 举例 解决方法 补充 问题 Type ...

  3. TypeError: not all arguments converted during string formatting报错解决

    python字符串格式转换报错 # 学习者:xinkai # 时间:2023/1/3 10:45 list1=[int(i) for i in input().split()] sum=0 for i ...

  4. 解决python中TypeError: not enough arguments for format string

    解决python中TypeError: not enough arguments for format string for i in range(1,10):​ for j in range(1,i ...

  5. cloud foundry部署报错TypeError: can't convert Hash into String

    报错:TypeError: can't convert Hash into String The first thing I notice is you are running Ruby 1.8 on ...

  6. python向数据库传输数据时弹出not enough arguments for format string怎么办

    cursor.executemany 为批量操作,批量就是一次能写入多行数据 传入cursor.executemany(sql, values)的values参数,应是多行的,即 [(一组数据),(另 ...

  7. 【TypeError: float() argument must be a string or a number, not ‘map’】

    初始 相关系数过滤法调用函数 from sklearn.feature_selection import SelectKBest from scipy.stats import pearsonr Se ...

  8. vue-router.esm.js?ac56:2316 TypeError: Cannot create property ‘_Ctor‘ on string ‘H‘

    报错: vue-router.esm.js?ac56:2316 TypeError: Cannot create property '_Ctor' on string 'H' 错误的把配置项route ...

  9. TypeError: Cannot create property ‘csrq‘ on string ‘‘“

    TypeError: Cannot create property 'csrq' on string ''" 在使用子组件时如果子组件一开始要求传参,但是在另一个页面中不需要传参时一般会有这 ...

  10. TypeError: ord() expected a character, but string of length 6 found

    错误如下 ord()  期待是一个字符,你使用了string 所以转ASCII 的时候需要注意了, 里面是字符 ,比如 ord("a")   , 修改下把

最新文章

  1. pythonfor循环语句1到7、不要4_【IT专家】关于Python中的for循环控制语句
  2. 开发源码常用网站参考
  3. instancing render
  4. 前端学习(3235):react生命周期2
  5. 男孩子什么品质最吸引女生?
  6. SpringCloud微服务架构学习(二)常见的微服务架构
  7. ES6 String和Number扩展
  8. LeetCode3 无重复字符的最长子串
  9. 用计算机怎么按四分之三次方等于多少,八十一分之十六的负四分之三次方怎么算,要具体过程,答案是多少?...
  10. LogViewer_2
  11. html仿360首页动画效果图,仿360影视网站模板html源码
  12. 支付核心研发部 | POS支付系统技术架构解密
  13. udacity深度学习--2. 深度学习简介--LESSON5 Jupyter notebook
  14. H3C交换机常用命令(初学)
  15. QCustomplot之安装篇(一)
  16. 下载安装纯净版火狐浏览器的步骤
  17. 【山东OI选手福利!!!】汇编在Cena中的使用
  18. android gsm基站定位,通过SIM卡获取GPS,android基站定位原理
  19. datagrid 之修改
  20. 名编辑电子杂志大师教程 | 名编辑电子杂志大师能制作高清电子期刊吗?

热门文章

  1. H264 视频文件 帧格式 传输封装等
  2. 数字证书及其认证过程
  3. Chloe 蔻依 恋旅
  4. 愿天下有情人都是失散多年的兄妹 (25 分)
  5. java弹跳小球程序_用java实现跳动的小球示例代码
  6. 【C++】【内存】系列三:内存优化
  7. What You Must Know To Build Savvy Push Notifications(推送策略)
  8. 互联网产品经理必备文档介绍
  9. JQuery中$(document)、$(document).ready()是什么意思?
  10. 计算个人所得税的html,实验3-6 计算个人所得税 (10 分)