Python学习之路(5)——变量
1、声明变量
1
2
3
4
|
#!/usr/bin/env python # -*- coding: utf-8 -*- name = "wupeiqi" |
上述代码声明了一个变量,变量名为: name,变量name的值为:"wupeiqi"
变量的作用:昵称,其代指内存里某个地址中保存的内容
变量定义的规则:
- 变量名只能是 字母、数字或下划线的任意组合
- 变量名的第一个字符不能是数字
- 以下关键字不能声明为变量名
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
2、变量的赋值
#!/usr/bin/env python # -*- coding: utf-8 -*- name1 = "wupeiqi" name2 = "alex"
![](https://images2015.cnblogs.com/blog/425762/201510/425762-20151024180236677-1430341076.png)
#!/usr/bin/env python # -*- coding: utf-8 -*- name1 = "wupeiqi" name2 = name1
![](https://images2015.cnblogs.com/blog/425762/201510/425762-20151024180334849-979288684.png)