format
fn format(string fmt) -> string Import
Source: use string::{format}; compiler/src/builtin_docs/string.hy Builds a string from the literal fmt and the arguments that follow it.
format takes any number of arguments after fmt; each % specifier
in fmt consumes the next one:
%i: anint(orbyte) in decimal.%f: afloat(1.5,2.0).%s: astring.%z: abool(true/false).%v: any value with aShowinstance (enums, tuples, records, …).%x,%b,%u: anintin hex, binary, or unsigned decimal.%%: a literal%.
fmt must be a string literal: the compiler checks every specifier
against its argument’s type, and reports too many or too few arguments.
format is built into the compiler, not a library function.
Parameters#
| Name | Type |
|---|---|
fmt | string |
Returns#
string
Examples#
use string::{format};
use tests::assert;
assert!(format("%i-%s", 42, "x") == "42-x");
assert!(format("%f %z", 1.5, true) == "1.5 true");
assert!(format("%x %b %%", 255, 5) == "ff 101 %");
assert!(format("%v", (1, "a")) == "(1, a)");