算符
元素+运算符---》表达式---》函数
3**2=8幂运算
除法在python2为整数运算 3/2=1 python3为浮点数运算3/2=1.5
双整除 3//2 结果就是整数,取floor 向小的方向取值
python 中的and从左到右计算表达式,若所有值均为真,则返回最后一个值,若存在假,返回第一个假值。
and短路求值
表达式除了值外,还可能造成副作用,即造成环境改变,或执行某些操作
格式化字符串:常用于输出内容
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 3/2
1
>>> -3/2
-2
>>> -3//2
-2
lsx@sx-Inspiron-N301Z:~$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> -3/2
-1.5
>>> -3//2
-2
>>>
>>> 1+2 and 3*4 or 5**5
12
>>>
>>> 1+8 <=1+2*3
>>> False
>>> a=10
>>> b=(a=10) #有些表达式在语法上不可求值
File "<stdin>", line 1
b=(a=10)
^
SyntaxError: invalid syntax
>>> b=a=10 #语法糖 等价于 b=10 a=10
>>> name='shell'
>>> print('my name is {0}, and the length of name is {1}'.format(name,len(name)))
my name is shell, and the length of name is 5
>>> print('my name is %s and the length of name is %d' % (name,len(name)))
my name is shell and the length of name is 5
>>> print('hello,'+name+'welcom to python\'s world') #字符串拼接有开销
hello,shellwelcom to python's world
>>> print('hello, %s .welcom to python\'s world' % name)
hello, shell .welcom to python's world
>>> print('hello, %s. welcome to python\'s world' % name)
hello, shell. welcome to python's world
>>>