day 005总结

基本运算符

算术运算符

+ - * / % // **

比较运算符

> >= < <= == !=  #返回一个布尔值

赋值运算符

= += -= *= /= //= %= **=

逻辑运算符

and左右两个条件都为True,则为True,否则为False

or左右两个条件只要有一个满足则为True,否则为False

not 如果条件为True,则非False。如果条件为False,则非True。

身份运算符

用于比较两个对象的存储单元

is和is not

x=257
y=x
z=257

print(x is y)#is比较的是内存地址
print(x is not y)#is not判断是否不相等

位运算符

把数字看作二进制进行计算的

& | ^ - << >>

成员运算符

判断元素是否在容器类元素里面(字符串)

in 和not in

class_student_lt = ['s1','s2','s3']
print('s1' in class_student_lt) # True
print('s1' not in class_student_lt) # False
print('s4' in class_student_lt) # False

python运算符优先级

需要优先,就加括号,括号优先级最高

流程控制之if判断

单分支结构

if 条件:
    代码块

双分支结构

if 条件:
    代码块1(条件成立)
else:
    代码块2(条件不成立)

多分支结构

if 条件1:
    代码块1#条件1成立
elif 条件2:
    代码块2#条件1不成立条件2成立
elif 条件3:
    代码块3#条件1 2不成立条件3成立
elif可以有无限个
else:
    代码块4#所有条件不成立

流程控制之while循环

while 条件:
    代码块

while+break

while True:
    print(1)
    break#终止掉当前层的循环,执行其他代码
    print(2)

while+continue

while n<10:
    if n==8:
        continue#终止本次循环,直接进入下一次循环
    print(n)
    n+=1

tag控制循环

tag=True
while tag:
    代码块
    

while+else

n=1
while n<3:
    print(n)
    n+=1
else:
    print('else会在while,没有被break时才会执行else中的代码')

转载于:https://www.cnblogs.com/zqfzqf/p/11506841.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值