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

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中TypeError: not enough arguments for format string_第1张图片

解决python中TypeError: not enough arguments for format string_第2张图片


总结:在学习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))

你可能感兴趣的:(python,python,格式化输出,TypeError:,not,enough,argument)