日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Python编程基础:第九节 逻辑运算Logical Operators

發(fā)布時間:2025/4/5 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python编程基础:第九节 逻辑运算Logical Operators 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

第九節(jié) 邏輯運算Logical Operators

  • 前言
  • 實踐

前言

常用的邏輯運算共分為三種:與(and)、或(or)、非(not)。與運算就是同真才真,有假則假;或運算就是有真則真,同假才假;非運算就是真變假,假變真。我們接下來舉個例子加以分析。

實踐

我們從鍵盤獲取輸入作為今天的溫度,然后判斷若今天溫度滿足[0, 30],則輸出今天是個好天氣,適合出去玩耍:

temp = int(input("What is the temperature outside?: ")) if temp>=0 and temp<=30:print("the temperature is good today!")print("go outside!") >>> What is the temperature outside?: 15 >>> the temperature is good today! >>> go outside!

若今天溫度低于0°或高于30°我們就呆在家里:

temp = int(input("What is the temperature outside?: ")) if temp<0 or temp>30:print("the temperature is bad today!")print("stay inside!") >>> What is the temperature outside?: -2 >>> the temperature is bad today! >>> stay inside!

我們將上述兩段代碼進(jìn)行合并:

temp = int(input("What is the temperature outside?: ")) if temp>=0 and temp<=30:print("the temperature is good today!")print("go outside!") elif temp<0 or temp>30:print("the temperature is bad today!")print("stay inside!")

取反運算的使用方法如下:

if not(True):print("False") else:print("True") >>> True

以上便是邏輯運算的全部內(nèi)容,感謝大家的收藏、點贊、評論。我們下一節(jié)將介紹while循環(huán)(While Loops),敬請期待~

總結(jié)

以上是生活随笔為你收集整理的Python编程基础:第九节 逻辑运算Logical Operators的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。