Ad
  • Custom User Avatar

    .format() is older as it was introduced in python 2.6 while f-string is newer and from python 3.6

    F-strings are generally more compact than .format() and easier to decipher but the biggest difference is in the ability for expressions within the f-string to be performed at runtime. This allows for things such as calling functions, creating classes, and math operations.

    Additionally, f-strings are faster than .format()

  • Custom User Avatar

    Nice solution. I originally tried going the memoization route but worried about memory usage.