Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Whats wrong with line 12?
#1
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 :/
Reply
#2
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'))
Recommended Tutorials:
Reply
#3
Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,532 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Whats wrong with the elif? inunanimous93 3 2,440 Nov-30-2020, 03:58 AM
Last Post: deanhystad
  Whats Wrong!? rjay81 3 2,250 May-13-2020, 08:02 PM
Last Post: rjay81
  Can u see this code and tell whats wrong with it? AhmadKamal 14 5,291 Apr-29-2020, 11:09 AM
Last Post: jefsummers
  python gives wrong string length and wrong character thienson30 2 2,985 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  Whats a good design/approach? hshivaraj 1 1,764 Sep-16-2019, 01:44 AM
Last Post: snippsat
  elevator simulator...whats the wrong at this code? tasos710 5 5,896 Jun-11-2019, 01:38 AM
Last Post: micseydel
  whats the difference between sys.exit() and break? mitmit293 1 4,109 Jan-27-2019, 09:46 PM
Last Post: ichabod801
  Whats wrong with this code? student1 1 2,396 May-18-2018, 04:19 PM
Last Post: skorpius_
  I have no clue whats wrong... Jack_03 1 2,810 Sep-28-2017, 05:36 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020