How to use f-strings to distribute tuple values versus .format

Issue

This Content is from Stack Overflow. Question asked by Netforce23

So I just learned about f-strings, and I like how efficient they can be, but I was wondering if there’s a way I can use them to replicate something I do for some extremely simple code (mostly just math calculations for myself):

Say I have a function that returns a tuple:

def add(a, b):
   return a, b, a+b

I can then use that in a print statement with .format and * to distribute the contents of the tuple:

print("The sum of {} and {} is: {}".format(*add(1,2)))

Is there a way I can replicate this with an f-string?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?