大蟒日志2

八、Operators and Expressions (运算符与表达式)

  1. 两个表格
  2. 运算示例

2018.3.26
1.两个表格
运算符表格
运算符

python优先级列表
python优先级列表

2018.3.27
2.运算示例:

# 2018.3.26
''' 
Operators and Expressions:
单词:braces大括号{}   parentheses圆括号()   square brackets中括号[]    angle brackets中括号
Operators & Operands操作符和操作数    Boolean AND 布尔(逻辑)与
'''
# 2018.3.27
# 2.Ex.Area
length=7
breadth=2
area=length*breadth
print('Area is',area) # 注意显示结果中自动有空格填充在字符串和数字之间
print('Perimeter is',2*(length+breadth))
# 与C语言类似,但要简洁许多

#在IDLE中运行以下运算:
\>>> 2+3
5
\>>> 3*5
15
\>>> 'a'+'b'
'ab'
\>>> 'la'*3
'lalala'
\>>> -50+24
-26
\>>> 13/3
4.333333333333333
\>>> 20/5
4.0
\>>> 3.5/0.5
7.0
\>>> 13//3
4
\>>> 9/1.81
4.972375690607735
\>>> 9//1.81
4.0
\>>> 13%3
1
\>>> -25.5%2.25
1.5
\>>> 2<<2
8
\>>> 11>>1
5
\>>> 5 & 3
1
\>>> 5 | 3
7
\>>> 5^3
6
\>>> -5
-5
\>>> ~5
-6
\>>> 5 < 3
False
\>>> 5 > 3
True
\>>> x=3;y=5;z=3; x<y
True
\>>> x<=y
True
\>>> y>z
True
\>>> x==z
True
\>>> m='str';n='Str';m==n
False
\>>> m!=n
True
\>>> x=False;y=True;x and y
False
\>>> x or y
True
\>>> not y
False
\>>> 2+3*4
14
\>>> 2**(-1)
0.5

【声明】本博文为学习笔记,含有个人修改成分,并非完全依照《a byte of python》,仅供参考。若发现有错误的地方,请不吝赐教,谢谢。同时,我也会不定期回顾,及时纠正。#

猜你喜欢

转载自blog.csdn.net/csdner_0/article/details/79822316