Think Python 学习笔记2:变量、表达式和声明
2014-02-25 23:41
501 查看
注意变量名的命名规则:
1、不能以数字开头开头;
2、只能包含字母、数字、下划线及其组合;
3、不能使用Python内部关键字作为变量名。
Python 2 一共有31个关键字:
and del from not while as elif global or with assert else if pass yield break except import print
class exec in raise continue finally is return def for lambda try
Python中基本运算符有:+、-、*、/和**,分别代表:加、减、乘、除和乘方。
Python的运算优先级:括号>乘方>乘法=除法>加法=减法,同一优先级按照从左往右运算。
无论啥编程语言,如果不确定其运算优先级,就用 括号 。
字符串运算符:+和*,例子最容易看懂了:'Oh'+' Yeah' = 'Oh Yeah' ; 'Shit'*3 = 'ShitShitShit'
关于注释:不要做多余的注释,但要做足够的注释。
附上名人名言一句:It is reasonable to assume that the reader can figure out what the code does; it is much more useful to explain
why. (By the Author of the Book)
1、不能以数字开头开头;
2、只能包含字母、数字、下划线及其组合;
3、不能使用Python内部关键字作为变量名。
Python 2 一共有31个关键字:
and del from not while as elif global or with assert else if pass yield break except import print
class exec in raise continue finally is return def for lambda try
Python中基本运算符有:+、-、*、/和**,分别代表:加、减、乘、除和乘方。
Python的运算优先级:括号>乘方>乘法=除法>加法=减法,同一优先级按照从左往右运算。
无论啥编程语言,如果不确定其运算优先级,就用 括号 。
字符串运算符:+和*,例子最容易看懂了:'Oh'+' Yeah' = 'Oh Yeah' ; 'Shit'*3 = 'ShitShitShit'
关于注释:不要做多余的注释,但要做足够的注释。
附上名人名言一句:It is reasonable to assume that the reader can figure out what the code does; it is much more useful to explain
why. (By the Author of the Book)
相关文章推荐
- python之明密文转换
- wxpython ubuntu statusbar not showing
- python for android : 手机摇一摇
- 《Python》学习笔记
- Python3的变化
- 使用 Python 模拟登录查询
- pip安装python包出错:ctype = ctype.encode(default_encoding) # omit in 3.x!
- python 科学计算学习一:numpy快速处理数据(1)
- 【PythonChallenge】Level 5
- python 信号处理句柄第二个参数的作用
- 使用ctypes调用kernel32.dll中的函数
- Python的switch实现
- python中常见的日期换算
- 解决Python提示No module named 'pkg_resources'错误
- python参考手册--第10、11章执行环境、调试
- 【Python编程】网页URL提取实例
- Python的常见几道数学运算题
- Python 处理理时间超详细转的
- Python源码剖析----第三章(下)
- storm安装(2)ZeroMQ、JZMQ、Python、Java环境的安装