1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | """ -----------bool运算符、比较运算符学习---------- bool 运算符 Ture/False,注:Ture本质上是一个数字即1,False是0 使用方式: bool 或 使用比较运算符(>、<、=、>=、<=、==) 字符串可拼接,bool 不可拼接 """ isSuccess = True print (f "isSuccess={isSuccess}" ) isOk = 10 > 8 print (f "isOk: {isOk}" ) print ( "isOk is %s" % isOk) print ( "isOk is {}" . format (isOk)) print ( "isOk is " + str (isOk)) boolStr1 = True # 1 boolStr2 = False # 0 print ( "True + False = " ,boolStr1 + boolStr2, "Ture本质上是一个数字即1,False是0" ) print (f "方式一,bool 比较:{boolStr1 == boolStr2}" ) print ( "方式二,bool 比较:%s" % str (boolStr1 = = boolStr2)) # 字符串可拼接,bool 不可拼接 print ( "方式三,bool 比较:{}" . format (boolStr1 = = boolStr2)) print ( "方式四,bool比较:" + str (boolStr1 = = boolStr2)) # 字符串可拼接,bool 不可拼接 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | """ python 中判断语句的使用 1.python 中使用判断语句时,注意 : 2.if 判断语句的代码块,需缩进4个空格(一个Tab) 3.and or not:优先级是 not > and > or """ print ( "\r\n请输入你的年龄" ) age = input () # input()函数默认返回值为字符串 # if int(age) >= 18 and int(age) < 80: if 18 < = int (age) < 80 : print (f "你已是{age}成年人" ) elif int (age) > = 80 : print (f "你已是{age}高寿老人" ) else : print (f "你还是{age}未成年人" ) |
示例二:运行结果略
1 2 3 4 5 6 7 8 9 10 | print ( "\r\n----------玩玩猜猜我是谁,你有三次机会哦----------" ) name = "kunkun" if input ( "请输入你的姓名" ) = = name: print ( "恭喜你,太厉害了第一次就猜对" ) elif input ( "猜错了,再来一次" ) = = name: print ( "恭喜你,猜对了" ) elif input ( "猜错了,还剩最后一次机会哦" ) = = name: print ( "恭喜你,终于猜对了" ) else : print (f "抱歉,猜错喽" ) |
博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本