What is the easiest way to pad a string with 0 to the left?

The fmt module documentation describes all the formatting options: Fill / Alignment The fill character is provided normally in conjunction with the width parameter. This indicates that if the value being formatted is smaller than width some extra characters will be printed around it. The extra characters are specified by fill, and the alignment can … Read more

What are the supported Swift String format specifiers?

The format specifiers for String formatting in Swift are the same as those in Objective-C NSString format, itself identical to those for CFString format and are buried deep in the archives of Apple Documentation (same content for both pages, both originally from year 2002 or older): https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFStrings/formatSpecifiers.html https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html But this documentation page itself is incomplete, … Read more

String with ‘f’ prefix in python-3.6

See PEP 498 Literal String Interpolation: The expressions that are extracted from the string are evaluated in the context where the f-string appeared. This means the expression has full access to local and global variables. Any valid Python expression can be used, including function and method calls. So the expressions are evaluated as if they … Read more

What is the difference between !r and %r in Python?

%r is not a valid placeholder in the str.format() formatting operations; it only works in old-style % string formatting. It indeed converts the object to a representation through the repr() function. In str.format(), !r is the equivalent, but this also means that you can now use all the format codes for a string. Normally str.format() … Read more