2009-02-12 160 views
5

我看到你們使用Python的字符串格式化

url = '"%s"' % url # This part 

>>> url = "http://www.site.com/info.xx" 
>>> print url 
http://www.site.com/info.xx 
>>> url = '"%s"' % url 
>>> print url 
"http://www.site.com/info.xx" 

它是高級Python?有沒有教程呢?我怎樣才能瞭解它?

+0

避免像txts一樣寫入。 – 2009-02-12 21:39:05

+0

Duplicate:http://stackoverflow.com/questions/1225637/python-string-formatting – bignose 2010-03-23 13:06:10

+4

你已經將兩個問題都標記爲重複。當然,你只會標記後者(按時間順序) – 2012-12-30 06:35:17

回答

0

它不先進,可以用「或」來定義字符串。

檢查documentation

3

沒有,但//徵求意見肯定是高級Python嘗試徵求意見一#前綴

14

這是常見的字符串格式化,並且非常有用它類似於。到C風格的printf格式。請參閱Python.org文檔中的String Formatting Operations。你可以使用像這樣的多個參數:

"%3d\t%s" % (42, "the answer to ...")