您的位置:首页 > 编程语言 > Python开发

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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: