Python_day02_2018.7.3

一.格式化输出

print("%s今年%s岁,爱好是%s,性别是:%s"  %  (name,age,hobby,gender))

%s 叫做占位符,(字符串) 

%d叫做占位符,(整型,数字)

二.基本运算符

1.算数运算

+ 加 10+20=30

- 减  20-10= 10

* 乘 10*10=100

/ 除法   3/2=1.3

% 取余 3/%2=1

// 商取整 3//2=1

2.比较运算

= 等于

!= 不等于    <>  也是不等于

> 大于

<小于

>= 大于等于

<=小于等于

3.赋值运算

a=10

b=20

4.逻辑运算

not:真假反过来

and :同真为真,有假为假

or  :有真为真,全假为假

运算顺序:  not =>and => or

1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6  ==> True
# 2)not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 ==>Flase

1),8 or 3 and 4 or 2 and 0 or 9 and 7  ==>8
# 2),0 or 2 and 3 and 4 or 6 and 0 or 3 ==>4

 1)、6 or 2 > 1   ==>6
# 2)、3 or 2 > 1 ==>3
# 3)、0 or 5 < 4 ==>Flase
# 4)、5 < 4 or 3 ==>3
# 5)、2 > 1 or 6 ==>True
# 6)、3 and 2 > 1 ==>True
# 7)、0 and 3 > 1 ==>0
# 8)、2 > 1 and 3 ==>3
# 9)、3 > 1 and 0 ==>0
# 10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2 ==>2

猜你喜欢

转载自www.cnblogs.com/kcwxx/p/9260526.html