python if语句and_Python -- 逻辑运算符 -- and -- if语句

这篇博客介绍了Python编程中的关键字列表,包括and、or、not等,并展示了如何使用它们进行逻辑判断。此外,还讲解了比较操作的优先级以及三元运算符的用法。同时,涉及到了字符串的in和not in操作以及条件判断语句的使用,如if-else和嵌套判断。最后,通过实例演示了变量赋值、条件表达式以及字符串方法的运用。
摘要由CSDN通过智能技术生成

import keyword

print(keyword.kwlist)

# ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break',

# 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally',

# 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal',

# 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

# a = 5

# b = 10

# c = 6

# print(a != b)

# print(a

# print(1>2 and 3 < 4 or 4>5 and 2 > 1 or 9< 8)

# 优先级 () not and or

# x or y x为真就是x 否y

# x and y x为真就是y 否x

# not x x为真就是false 否 true

# in 在什么什么里面

# not in 不在什么什么里面

print('ni' not in 'nihaoma')

# 三元运算符

# 结果1 if 条件 else 结果2 true就是 if左边的 否 右边

re = 55 if 3 > 2 else 66

print(re)

print('if' in keyword.kwlist)

---------------------------------------------------------------------------------------------

import keyword

# print('if' in keyword.kwlist) #查看if是否是关键字

# if 表达式 :

# if 5<3 :

# print('张飞')

# print('李艳')

# if 条件:

# pass

# else:

# pass

# a,b=5,3

# if a>b :

# print(a)

# else:

# print(b)

# 嵌套if

a,b,c = 5,3,2

# if a>b:

# if a>c:

# print(a)

# else:

# print(c)

# else:

# if b>c:

# print(b)

# else:

# print(c)

# 多重判断

# score = 99;

# if score >= 0 and score <= 60:

# print('及格')

# elif score >= 61 and score <= 80:

# print('良好')

# elif score >=81 and score <=100:

# print('优秀')

if len('1') > 3:

print('长')

if 'nihao'.startswith('ni'): #以什么开头startswith

print(True)

if (i := 5) < 3:

print(i)

if (n := len(a)) > 3 :

print('你好')

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值