python学习之路-day1

1 变量

赋值:变量可以是字符串、序列、元组、

 1 # author:hams.ali
 2 
 3 # 界面
 4 line = '-*'*20
 5 # 数字直接可以计算
 6 
 7 _var1 = '23'
 8 
 9 # 字符变量拼接
10 _var_2 = '
	my 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, '	', year, moth, day)
24 print(line)# 分割
25 
26 record = ['Dave', 'dave@example.com', '773-555-1212', '847-555-1212']
27 name, email, *phone_numbers = record
28 print('name:{}
email:{}
phone:{}'.
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:dave@example.com
phone:['773-555-1212', '847-555-1212']
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

原文地址:https://www.cnblogs.com/hams-ali/p/11538074.html