這篇文章沒有什麼主題,純粹的是記錄學習過程中要注意的地方。
-------------------------------------
-------------------------------------import os # 包含系統模組
# getcwd()方法取到當前目錄
# listdir()方法列出指定目錄下的檔案、資料夾
print os.listdir(os.getcwd())
python對編碼的問題非常糾結
------------------冒泡-------------------
-------------------插入------------------------#!-*-coding:utf-8-*-
# bubble sort
# from shhider
def main():
#**********= string->int
numstr = raw_input()
nums = numstr.split()
le = len(nums) # 輸入的數字的個數
for i in xrange(le):
nums[i] = int( nums[i] )
#print nums
#**********===
for x in xrange( le-1 ):
for y in xrange( le-x-1 ):
if nums[y] > nums[y+1]:
temp = nums[y]
nums[y] = nums[y+1]
nums[y+1] = temp
print nums
if __name__ == '__main__':
main()
-----------------格式化輸出字典內容---------------------------#!-*-coding:utf-8-*-
# insert sort
# from shhider
def main():
#**********= string->int
numstr = raw_input()
nums = numstr.split()
le = len(nums) # 輸入的數字的個數
for i in xrange(le):
nums[i] = int( nums[i] )
#print nums
for x in xrange(1,le):
key = nums[x]
y = x
while nums[y-1]>key and y>0: # 注意邏輯運算子
nums[y] = nums[y-1]
y = y-1 # 沒有自增、自減
nums[y] = key
print nums
if __name__ == '__main__':
main()
import json;
# demodictlist is the value we want format to output
result = json.dumps(demodictlist, indent=1)
print result
python教學筆記 python學習筆記(一)
1.eval 函式 eval是單詞evaluate的縮寫,就是 求.的值的意思。eval 函式的作用是把str轉換成list,dict,tuple.li 1 1,2,3 print eval li 1 di 1 print eval di 1 tu 1 2,4,6 print eval tu 1 執...
python學習筆記
coding utf 8 coding utf 8 應該像八股文一樣在每個指令碼的頭部宣告,這是個忠告 為了解決中文相容問題,同時你應該選擇支援 unicode 編碼的編輯器環境,保證在執行指令碼中的每個漢字都是使用 utf 8 編碼過的。cdays 5 exercise 3.py 求0 100之間...
Python 學習筆記
python 學習筆記 def run print running.def execute method method execute run result running.condition false test yes,is true if condition else no,is false ...