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

歡迎訪問 生活随笔!

生活随笔

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

python

python关键字和保留字_或带有Python示例的关键字

發(fā)布時(shí)間:2023/12/1 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python关键字和保留字_或带有Python示例的关键字 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

python關(guān)鍵字和保留字

Python或關(guān)鍵字 (Python or keyword)

or is a keyword (case-sensitive) in python, it is a logical operator actually, it is used to validate more than one conditions. It is similar to Logical OR (||) operator in C, C++ programming. It requires a minimum of two conditions and returns True – if one or more condition(s) is/are True.

還是 python中的一個(gè)關(guān)鍵字(區(qū)分大小寫),實(shí)際上它是一個(gè)邏輯運(yùn)算符,用于驗(yàn)證多個(gè)條件。 它類似于C , C ++編程中的邏輯OR(||)運(yùn)算符。 它至少需要兩個(gè)條件并返回True –如果一個(gè)或多個(gè)條件為True 。

Truth table for "or" keyword/operator

“或”關(guān)鍵字/運(yùn)算符的真值表

Condition1 Condition2 (Condition1 or Condition2) True True True True False True False True True False False False

Syntax of or keyword/operator:

或關(guān)鍵字/運(yùn)算符的語法:

condition1 or condition2

Example:

例:

Input:a = 10b = 20# conditionsprint(a>=10 or b>=20)print(a>10 or b>20)Output:TrueFalse

或運(yùn)算子的Python范例 (Python examples of or operator)

Example1: Take two numbers and test the conditions using or operator

例1:取兩個(gè)數(shù)字并使用或運(yùn)算符測試條件

# python code to demonstrate example of # or keyword/operatora = 10 b = 20# printing return values print(a>=10 or b>=20) print(a>10 or b>20) print(a==10 or b==20) print(a==10 or b!=20)

Output

輸出量

True False True True

Example 2: Input a number and check whether it is divisible by 2 or 3

示例2:輸入一個(gè)數(shù)字并檢查它是否可以被2或3整除

# Input a number and check whether # it is divisible by 2 or 3# input num = int(input("Enter a number: "))# checking num is divisible by 2 or 3 if num%2==0 or num%3==0:print("Yes, ", num, " is divisble by 2 or 3") else:print("No, ", num, " is not divisble by 2 or 3")

Output

輸出量

First run: Enter a number: 66 Yes, 66 is divisble by 2 or 3Second run: Enter a number: 5 No, 5 is not divisble by 2 or 3

Example 3: Input a string and check whether it is "Hello" or "World"

示例3:輸入一個(gè)字符串并檢查它是“ Hello”還是“ World”

# Input a string and check # whether it is "Hello" or "World"# input string = input("Enter a string: ")# checking the conditions if string=="Hello" or string=="World":print("Yes, \"", string, "\" is either \"Hello\" or \"World\"") else:print("No, \"", string, "\" is neither \"Hello\" nor \"World\"")

Output

輸出量

First run: Enter a string: Hello Yes, " Hello " is either "Hello" or "World"Second run: Enter a string: World Yes, " World " is either "Hello" or "World"Third run: Enter a string: IncludeHelp No, " IncludeHelp " is neither "Hello" nor "World"

翻譯自: https://www.includehelp.com/python/or-keyword-with-example.aspx

python關(guān)鍵字和保留字

總結(jié)

以上是生活随笔為你收集整理的python关键字和保留字_或带有Python示例的关键字的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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