Stream: beginners

Topic: template string


view this post on Zulip nandi (Feb 22 2025 at 13:27):

is there a template string where I can do something like {"foo": "bar"} rather than "{\"foo\":\"bar\"}"

view this post on Zulip Sam Mohr (Feb 22 2025 at 13:29):

You can do a multiline string to avoid needing the escapes

multiline_str =
    """
    {"foo": "bar"}
    """

view this post on Zulip Sam Mohr (Feb 22 2025 at 13:30):

But we don't have template strings like in JS, especially the feature where you can call a function on the string

view this post on Zulip Sam Mohr (Feb 22 2025 at 13:31):

But you can do interpolation on single line strings as well as multiline strings with

view this post on Zulip Sam Mohr (Feb 22 2025 at 13:31):

multiline_str =
    """
    { "foo": ${Inspect.to_str(bar)} }
    """

Last updated: Jul 26 2025 at 12:14 UTC