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..