Tchaikov’s Journal

June 1, 2006

Python 的点点滴滴 — dict 和 %

Filed under: Python

这里看来的。print 竟然可以这样玩!

dict = {\"name\": \"Guido\"}
print \"Hello %(name)s!\" % dict

可以注意到, %(name)s 中,name 是 dict 的 key,而 s 则是 format string。
读过 OSCON 2005 Effective Python Programming slides 之后,我看到刚才链接里的文章把 Python 的 Template 模式玩到了新的高度,令人咋舌不已。感叹道:
Python,你真是太邪门了!

1 Comment »

The URI to TrackBack this entry is: http://tchaikov.blogsome.com/2006/06/01/p28/trackback/

  1. 长见识了

    Comment by manman — January 28, 2007 @ 12:48 pm

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Get free blog up and running in minutes with Blogsome
Theme designed by Jay of onefinejay.com