Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to use .format?
#1
Hi,

I would like to add degree at the end of the phrase.
"Il fait: {}".format(str(w.temperature('celsius')['temp']))
Like:

"Il fait: {}".format(str(w.temperature('celsius')['temp'], "degree"))

but its not how to do it. anyone know how?
Reply
#2
Try
"Il fait: {} degrés.".format(str(w.temperature('celsius')['temp']))
Frankduc likes this post
Reply
#3
I should of tried that before.
Thank you Gribouillis
Reply
#4
Should not use str as gone be inside a string(that is of type str)
Also make more sense now to use f-string as it has been in Python now for 6-years.
print(f"Il fait: {w.temperature('celsius')['temp']} degrés.")
Reply


Forum Jump:

User Panel Messages

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