3
2

More than 5 years have passed since last update.

Python にて C/C++ の printf の 如き 書式 つき 出力を おこなふ

Last updated at Posted at 2015-01-21

たとへば

print "year:%d, month:%d, day:%d" % (year, month, day)

すなはち 演算子 '%' ぞ その肝 なる。
演算子 '%' は 數値にては modulo 演算の 意なれども Unicode 文字列にては 書式化として overload さる。
"format % values" にて format の中の % 變換 指定は values の中の 0 個 或いは それ以上の 要素にて 置き換へらる。

ちなみに C++ の boost::format() にては

std::out << boost::format("year:%d, month:%d, day:%d") % year % month % day;
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2