在一个打印功能的Python打印数组 [英] Python print array in one print function

查看:1496
本文介绍了在一个打印功能的Python打印数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有两个元素的数组=数组['ABC','高清']。
 如何打印只用一个函数整个阵列。像这样:打印%s和%s%阵列
可能吗?我有elemnts的predefined数,所以我知道有多少元素会在那里。

编辑:

我作出SQL INSERT语句,这样会有一些凭据,让我们说7,而在我的例子就应该是这样的:

 (插入到用户的值(%S,\\'%s的\\',......);%数组)


解决方案

您也可以做

 打印{0}和{1}。格式(ARR [0],ARR [1])

或你的情况

 打印插入到用户的值({0},{1},{2},...);格式(ARR [0],ARR [1] ARR [2] ...)

 打印插入到用户的值({0},{1},{2},...);格式(* ARR)

幸福吗?
使数组的长度确定的指数相匹配。

For example I have an array of two elements array = ['abc', 'def']. How do I print the whole array with just one function. like this: print "%s and %s" % array Is it possible? I have predefined number of elemnts, so i know how many elements would be there.

EDIT:

I am making an sql insert statement so there would be a number of credentials, let's say 7, and in my example it would look like this:

("insert into users values(%s, \'%s\', ...);" % array)

解决方案

you can also do

print '{0} and {1}'.format(arr[0],arr[1])

or in your case

print "insert into users values({0}, {1}, {2}, ...);".format(arr[0],arr[1],arr[2]...)

or

print "insert into users values({0}, {1}, {2}, ...);".format(*arr)

happy? make sure length of array matches the index..

这篇关于在一个打印功能的Python打印数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆