Printing ๐จ๏ธ & Formatting ๐โ
In this section, we will figure out in the printing to stdout and stderr using built-in functions / macros.
Printing ๐จ๏ธโ
Standard Output (stdout)โ
Python uses the built-in function print() to write output to stdout
(Docs).
To remove or change space between objects to print you can provide sep keyword argument.
To remove or change new line at the end, you can use end keyword argument.
Rust uses build-in macros println!() to write output to stdout
(Docs).
To remove or change space between objects to print should do it manually.
To remove new line at the end, you should use another built-in macro print!
(Docs).
Output will be:
Standard Error (stderr)โ
To print something in stderr you can modify file keyword argument to sys.stderr.
To remove or change space between objects to print you can provide sep keyword argument.
To remove or change new line at the end, you can use end keyword argument.
Output will be:
Formatting ๐โ
In latest Python version the best approach to format strings and data types is f-string or formatted string literal (declared with f"{}")
(f-string docs,
.format() docs).
In Rust standard approach to format string and data types is std::fmt or format! macro (declared "{}").