String formatting: % vs. .format vs. f-string literal

Python 2.6 introduced the str.format() method with a slightly different syntax from the existing % operator. Which is better and for what situations? Python 3.6 has now introduced another string formatting format of string literals (aka “f” strings) via the syntax f”my string”. Is this formatting option better than the others? The following uses each … Read more

How to format strings in Java

In addition to String.format, also take a look java.text.MessageFormat. The format less terse and a bit closer to the C# example you’ve provided and you can use it for parsing as well. For example: int someNumber = 42; String someString = “foobar”; Object[] args = {new Long(someNumber), someString}; MessageFormat fmt = new MessageFormat(“String is \”{1}\”, number … Read more