内容目录
def a(x,y): print("%s : %s "%x,y)
如上代码,我定义了个含两个参数的函数,传参时报错如下。
TypeError: not enough arguments for format string
将参数用括号括起后(如下所示),问题就解决了。
def a(x,y): print("%s : %s "%(x,y))
总结:在学习 python 时,要注意下 python 版本
python3.0 以后,在 print 后要加括号,
对一般输出:
python2 要这么写
print'helloworld'
python3.x 要这么写
print('helloworld')
格式化输出:
python2 要这么写
def a(x,y): print("%s : %s "%x,y)
python3.x 要这么写
def a(x,y): print("%s : %s "%(x,y))
————————————————
版权声明:本文为 CSDN 博主「monaxu」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/w926498/article/details/80579520
相关文章
- 使用Jetson_benchmark进行性能测试(0)
- 【Python】修改Windows中 pip 的缓存位置与删除 pip 缓存(1)
- 记录问题解决的连接(0)
- Python 格式化输出 —— 小数转化为百分数(0)
- ‘%s=%s’ % (k, v) for k, v in params.items(), ^ SyntaxError: Generator expression must be parent(0)