1.函式
代碼:
def test(x,y): print(x) print(y) test(y=2,x=1)#關鍵字引數 與形參順序無關 test(1,2)#位置引數 與形參一一對應 test(1,y=2)#如果有多個引數,關鍵字引數要放在位置引數后面View Code
2.進度條
import sys,time #匯入包 for i in range(20): sys.stdout.write("#") #終端列印# sys.stdout.flush() #立即寫入記憶體 time.sleep(0.1) #控制時間0.1SView Code
3.區域變數與全域變數
x=0 #全域變數 def test(): x=1 #區域變數 只作用于當前函式內(只有字串和整數不能修改,對于陣列或字典等復雜的物件可以修改) print(x) print(x) def test_2(): global x# 使用global 方法將區域變數宣告成全域變數 x=2 print(x) test() test_2()View Code
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/95143.html
標籤:Python
上一篇:python學習之路-day2
下一篇:python學習之路-day4
