python - How to use string formatting in specific size based variables? -


i know when use

"%2d"%(x) 

i string of x , in @ least size of 2, , if length of x shorter 2 spaces before it. how can give 2 variable too? example:

"%nd"%(2,1) ' 1' 

is possible in python? or need create loop it?

use * , actual width read next element of tuple of values, , value convert 1 following:

>>> "%*d" % (2, 1) ' 1' 

this documented in string formatting operations section of documentation — says:

  1. minimum field width (optional). if specified '*' (asterisk), actual width read next element of tuple in values, , object convert comes after minimum field width , optional precision.

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -