user1467267
user1467267

Reputation:

Python print skip arguments

I have this dirty short line of code printing a formatted date:

print '%f %d' % math.modf(time.time())

Now the modf method gives back two arguments, so the print function expects both. In the sake of purely doing this, and not the simple alternative of putting the output separately in a variable; is there any existing way of excepting parameters in print or is there any way to call specific argument-indexes?

For example I have 3 arguments in a print:

print '%s %d.%f' % 'Money',19,.99

I want to skip the first String-parameter that is parsed. Is there any way to do this?

This is mainly a want-to-know-if-possible question, no need to give alternative solutions :P.

Upvotes: 1

Views: 1900

Answers (1)

Not in "old school" string formatting.

But the format method of strings does have this ability.

print "{1}".format ("1","2")

The above will skip the "1" and will only print "2".

I hope you don't mind I gave an alternative despite you not asking for it :)

Upvotes: 2

Related Questions