Str.format or f strings?

Exercise 14

In exercise 14 on using formatting in strings it is required to use the str.format() method. I have been using the f string method instead. Is not the f string method the newer version? I find the f string method easier to write and understand and I am not sure why the older version is being taught. I also cannot get the correct answer without using str.format(), even if the answer is correct.

poem_desc = (f’The poem “{title}” is written by {poet}') f string method
poem_desc = “The poem "{}" is written by {}.”.format(title, poet) str.format() method

Newer doesn’t mean better, both have their uses. format() still tends to be useful for more complicated cases

for example here you can build many sentences from this one template

template = "The {food} is {adjective}."
sentence = template.format(food="apple", adjective="red")
1 Like