日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

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

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

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

  • 前言
  • 實(shí)踐

前言

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

實(shí)踐

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

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!")

取反運(yùn)算的使用方法如下:

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

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

總結(jié)

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

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