python关键字和保留字_或带有Python示例的关键字
python關鍵字和保留字
Python或關鍵字 (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中的一個關鍵字(區(qū)分大小寫),實際上它是一個邏輯運算符,用于驗證多個條件。 它類似于C , C ++編程中的邏輯OR(||)運算符。 它至少需要兩個條件并返回True –如果一個或多個條件為True 。
Truth table for "or" keyword/operator
“或”關鍵字/運算符的真值表
Condition1 Condition2 (Condition1 or Condition2) True True True True False True False True True False False FalseSyntax of or keyword/operator:
或關鍵字/運算符的語法:
condition1 or condition2Example:
例:
Input:a = 10b = 20# conditionsprint(a>=10 or b>=20)print(a>10 or b>20)Output:TrueFalse或運算子的Python范例 (Python examples of or operator)
Example1: Take two numbers and test the conditions using or operator
例1:取兩個數字并使用或運算符測試條件
# 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 TrueExample 2: Input a number and check whether it is divisible by 2 or 3
示例2:輸入一個數字并檢查它是否可以被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 3Example 3: Input a string and check whether it is "Hello" or "World"
示例3:輸入一個字符串并檢查它是“ 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關鍵字和保留字
總結
以上是生活随笔為你收集整理的python关键字和保留字_或带有Python示例的关键字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 飞利浦电视键盘数字如何输
- 下一篇: 枪口下的女谍剧情介绍