python新手學習

2021-08-10 20:20:50 字數 438 閱讀 8670

python新手,使用python2.7時遇到了以上的問題,原因大概是:python在安裝時,預設的編碼是ascii,當程式中出現非ascii編碼時,python的處理常常會報類似這樣的錯誤。在網上搜尋到了可行的解決方法:

在python的lib\site-packages資料夾下新建乙個sitecustomize.py,內容為:

#encoding=utf8 

import sys

reload(sys)

sys.setdefaultencoding('utf8')

重啟python直譯器,執行sys.getdefaultencoding(),檢視預設編碼,發現編碼已經被設定為utf8的了,

這是因為系統在python啟動的時候,自行呼叫該檔案,設定系統的預設編碼,而不需要每次都手動的加上解決**。

Python新手學習(二)

7.操作列表 for 新儲存變數 in 原儲存變數 在python中,for語句的範圍為其下面所縮排的行數,而c語言for擁有其 來約束範圍,不要忘記for最後的冒號 way bicycle air subway plane motor for mine in way print mine prin...

Python新手學習(三)

11.判斷 布林 檢查是否相等和不相等,對於字串來說,大小寫也是需要注意的點,大小寫不同會被判斷為不相等。laptop dell print laptop dell print laptop dell print laptop lenovo print laptop dell 結果,符合時返回tru...

Python2 7 14新手學習

python2.7.14 讓使用者選擇乙個功能,然後對其進行操作的例子。中間有問題的是年齡沒有做是否是數字判斷 usr bin python coding utf 8 print 1.新增乙個字典 print 2.查詢乙個字典 infos while true num raw input 請選擇1到...