Something like " some sentence ... # {value} ... "
in ruby.
If you search, you can find out how to use% as a conversion specifier or use the format function.
However, in the former introduction example, I felt that the line of sight was back and forth, and I had the impression that the format function was so long.
from functools import partial
myprint = partial(print, sep='')
hex_value = 0x1234
myprint('the value is %x'%hex_value,' and...')
You can get close to each variable by separating the strings with ,. In the above example, the space insertion in is prevented, but if there is no problem, the print function can be used as it is. I think it's okay because the output format is also specified. Please let me know if there is a better function.
(Addition) The formatted string literal that can be used in 3.6 and above was exactly what I was looking for. Thank you @naari. (See comments)
Recommended Posts