2

So this is my code but it returns error like this "Unknown format code 'e' for object of type 'str'". why??

c="*"*i
e=input01
d="{:>e}"
print(d.format(c))
1
  • please write what you are trying to achieve? what is your code supposed to do? what is the output you expect? Commented Mar 28, 2015 at 13:01

1 Answer 1

2

Pass e into the format as a variable, you are simply using the string "e" hence the error:

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

You can see actually passing the variable right adjusts the string correctly:

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

You could also remove the e from the format and pass it as the second arg to format:

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

Either way the {} after > is essential.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.