[Python] String Formatting
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Python] String Formatting相关的知识,希望对你有一定的参考价值。
One particularly useful string method is format
. The format
method is used to construct strings by inserting values into template strings. Consider this example for generating log messages for a hypothetical web server.
log_message = "IP address {} accessed {} at {}".format(user_ip, url, now)
If the variables user_ip
, url
and now
are defined then they will be substituted for the {}
placeholder values:
> print(log_message) IP address 208.94.117.90 accessed /bears/koala at 16:20
以上是关于[Python] String Formatting的主要内容,如果未能解决你的问题,请参考以下文章
r“string”b“string”u“string”Python 2/3比较