How to postpone/defer the evaluation of f-strings?

Here’s a complete “Ideal 2”. It’s not an f-string—it doesn’t even use f-strings—but it does as requested. Syntax exactly as specified. No security headaches since we are not using eval(). It uses a little class and implements __str__ which is automatically called by print. To escape the limited scope of the class we use the … Read more

PHP – how to create a newline character?

Only double quoted strings interpret the escape sequences \r and \n as ‘0x0D’ and ‘0x0A’ respectively, so you want: “\r\n” Single quoted strings, on the other hand, only know the escape sequences \\ and \’. So unless you concatenate the single quoted string with a line break generated elsewhere (e. g., using double quoted string … Read more

Is there a Python equivalent to Ruby’s string interpolation?

Python 3.6 will add literal string interpolation similar to Ruby’s string interpolation. Starting with that version of Python (which is scheduled to be released by the end of 2016), you will be able to include expressions in “f-strings”, e.g. name = “Spongebob Squarepants” print(f”Who lives in a Pineapple under the sea? {name}.”) Prior to 3.6, … Read more

Swift 3 incorrect string interpolation with implicitly unwrapped Optionals

As per SE-0054, ImplicitlyUnwrappedOptional<T> is no longer a distinct type; there is only Optional<T> now. Declarations are still allowed to be annotated as implicitly unwrapped optionals T!, but doing so just adds a hidden attribute to inform the compiler that their value may be force unwrapped in contexts that demand their unwrapped type T; their … Read more

How to interpolate variables in strings in JavaScript, without concatenation?

You can take advantage of Template Literals and use this syntax: `String text ${expression}` Template literals are enclosed by the back-tick (` `) (grave accent) instead of double or single quotes. This feature has been introduced in ES2015 (ES6). Example var a = 5; var b = 10; console.log(`Fifteen is ${a + b}.`); // “Fifteen … Read more