码迷,mamicode.com
首页 > 编程语言 > 详细

[Python] String Formatting

时间:2017-11-13 21:19:57      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:serve   bst   var   class   fine   python   ges   server   define   

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_ipurl 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

标签:serve   bst   var   class   fine   python   ges   server   define   

原文地址:http://www.cnblogs.com/Answer1215/p/7827928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!