Python Forum
trying to learn f-strings - puzzled by format() protocol
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to learn f-strings - puzzled by format() protocol
#1
the language reference section describing Formatted string literals says: "The result is then formatted using the format() protocol. The format specifier is passed to the __format__() method of the expression or conversion result." it is very unclear what is going on here. it seems like it is saying that it is formated twice (passing the result on to be formatted again). but the 2nd formatting makes no sense, if the result (presumably a string) is passed to __format__(). what normally happens there?

the examples look simple and make sense. but not understanding the described steps means i'm not going to know the subtle behavior with something strange, or weird bugs.

an online article says: "The expressions are evaluated at runtime and then formatted using the __format__ protocol. As always, the Python docs are your friend when you want to learn more." it has nice looking examples that don't give a solid understanding. it can't be my friend until i understand it.

i've already seen some heavy-duty use of f-strings that just didn't make sense, to me. at least, it didn't, yet. this is why i want a solid understanding of what is going on. there seems to be a more advanced level of understanding needed to be able to interpret all kings of f-string.

does anyone understand what i am not understanding? i know enough to make some working f-strings. but it seems my understanding has some serious gaps.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
trying to learn f-strings - puzzled by format() protocol - by Skaperen - Jul-25-2019, 05:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print a list strings is fast but printing the joined strings is slow Skaperen 9 3,959 Aug-26-2019, 07:48 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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