Python Forum
Whats wrong with line 12? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Whats wrong with line 12? (/thread-4778.html)



Whats wrong with line 12? - brimalm - Sep-08-2017

formatter = " {} {} {} {}"

print(formatter.format(1, 2, 3, 4))
print(formatter.format("one", "two", "three", "four"))
print(formatter.format(True, False, False, True))
print(formatter.format(formatter, formatter, formatter, formatter))
print(formatter.format(
    "I will",
    "try my",
    "own text",
    "here"))
print({}.format('but only because you told me to'))
I'm really new to this as you may very well understand.. Last line:

print({}.format('but only because you told me to'))

gives me the following error message:

Error:
Traceback (most recent call last): File "exercise8.py", line 12, in <module> print({}.format('but only because you told me to')) AttributeError: 'dict' object has no attribute 'format'
From what I understand my {} aren't working :/


RE: Whats wrong with line 12? - metulburr - Sep-08-2017

please use code tags next time

Quote:
print({}.format('but only because you told me to'))
this needs to be this
print('{}'.format('but only because you told me to'))



RE: Whats wrong with line 12? - brimalm - Sep-11-2017

Thank you!