1 變數 賦值:變數可以是字元串、序列、元組、 輸出效果: 2019 9 17-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*name subjet soce year moth dayali english 65 2019 9 17-*-*-*-*-*-*-*-*- ...
1 變數
賦值:變數可以是字元串、序列、元組、
1 # author:hams.ali 2 3 # 界面 4 line = '-*'*20 5 # 數字直接可以計算 6 7 _var1 = '23' 8 9 # 字元變數拼接 10 _var_2 = '\n\tmy age is ' + _var1 11 12 # 不可改變數值的組元 13 var = (2019, 9, 27) 14 15 # 變數解壓 16 x , y ,z=(2019, 9, 17) 17 print(x,y,z) 18 print(line)# 分割 19 # 多變數解壓 20 data = ['ali', 'english', 65, (2019, 9, 17)] 21 name, subjet, soce, (year, moth, day) = data 22 print('name', 'subjet', 'soce', 'year', 'moth', 'day') 23 print(name, subjet, soce, '\t', year, moth, day) 24 print(line)# 分割 25 26 record = ['Dave', '[email protected]', '773-555-1212', '847-555-1212'] 27 name, email, *phone_numbers = record 28 print('name:{}\nemail:{}\nphone:{}'.\ 29 format(name, email, phone_numbers)) 30 print(line)# 分割
輸出效果:
2019 9 17
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
name subjet soce year moth day
ali english 65 2019 9 17
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
name:Dave
email:[email protected]
phone:['773-555-1212', '847-555-1212']
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*