Formatting strings in python with variables -


so code returns error "unknown format code 'e' object of type 'str'". why??

c="*"*i e=input01 d="{:>e}" print(d.format(c)) 

pass e format variable, using string "e" hence error:

d = "{:>{e}}" print(d.format(c, e=e)) 

you can see passing variable right adjusts string correctly:

in [3]: c = "*" * 4     in [4]: e = "10"     in [5]: d = "{:>{e}}"     in [6]: d.format(c, e=e) out[6]: '      ****' 

you remove e format , pass second arg format:

d = "{:>{}}" print(d.format(c, e)) 

either way {} after > essential.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -