python簡單的格式化字串1.使用格式化字串%操作符來實現format = 'hello, %s, nice to %s you'values = ('tom','meet')print format % values不能使用序列代替元組,因為序列會被解釋為一個值格式化實數(浮點數),用%.(要保留的位元),例如:format = 'Pi with three decimal is %.3f!'import mathprint format % math.pi2.用模板字串from
最近開始學習Python,為整理思路,特此撰文以記之。1、一些基礎知識要學習一門程式設計語言,安裝其開發工具自然是必不可少的事情之一。本人此次基於windowshe和linux(ubuntu)學習Python,所以其開發工具的安裝也只論述windows和ubuntu環境下的安裝過程。windows環境下安裝:(1)開啟瀏覽器,輸入www.python.org並點擊Download連結。(2)在此可以看到Python 2.7或Python3.3或其他版本的Python Windows
Isinstance(object, classinfo)Return true if theobject argument is an instance of theclassinfo argument, or of a (direct or indirect) subclass thereof. Also return true ifclassinfo is a type object andobject is an object of that type. Ifobject is not
import osfor root, dirs, files in os.walk("rootdirectory"): for f in files: fileFullName = os.path.join(root, f) # do what you want to. 註:os.walk("rootdirectory")為每個以“rootDirectory”為父資料夾的子檔案夾(“rootDirectory”本身和之下的所有子孫檔案夾)返回一個三元組(dirpath,
很多文章都提到了 import codecs,的確!但是有的在處理unicode時只考慮utf-8,或者簡單utf-16.但是utf-16使用時還容易報錯,原因就是utf-16會預設檢測BOM(byte order mark),如果有的檔案建立時沒有,則python無法正常讀取,這是就要考慮utf_16_le等。------------------------------------utf_16、utf_16_le、utf_16_be、utf_8引用下:http://blog.csdn.net/