Python operator.lt()函数与示例
operator.lt()函數(shù) (operator.lt() Function)
operator.lt() function is a library function of operator module, it is used to perform "less than operation" on two values and returns True if the first value is less than the second value, False, otherwise.
operator.lt()函數(shù)是運營商模塊的庫函數(shù),它被用于在兩個值并返回true執(zhí)行“小于操作”如果第一值小于所述第二值, 假 ,否則。
Module:
模塊:
import operatorSyntax:
句法:
operator.lt(x,y)Parameter(s):
參數(shù):
x,y – values to be compared.
x,y –要比較的值。
Return value:
返回值:
The return type of this method is bool, it returns True if x is less than y, False, otherwise.
此方法的返回類型為bool ,如果x小于y ,則返回True ,否則返回False 。
Example 1:
范例1:
# Python operator.lt() Function Exampleimport operator# integers x = 10 y = 20print("x:",x, ", y:",y) print("operator.lt(x,y): ", operator.lt(x,y)) print("operator.lt(y,x): ", operator.lt(y,x)) print("operator.lt(x,x): ", operator.lt(x,x)) print("operator.lt(y,y): ", operator.lt(y,y)) print()# strings x = "Apple" y = "Banana"print("x:",x, ", y:",y) print("operator.lt(x,y): ", operator.lt(x,y)) print("operator.lt(y,x): ", operator.lt(y,x)) print("operator.lt(x,x): ", operator.lt(x,x)) print("operator.lt(y,y): ", operator.lt(y,y)) print()# printing the return type of the function print("type((operator.lt(x,y)): ", type(operator.lt(x,y)))Output:
輸出:
x: 10 , y: 20 operator.lt(x,y): True operator.lt(y,x): False operator.lt(x,x): False operator.lt(y,y): Falsex: Apple , y: Banana operator.lt(x,y): True operator.lt(y,x): False operator.lt(x,x): False operator.lt(y,y): Falsetype((operator.lt(x,y)): <class 'bool'>Example 2:
范例2:
# Python operator.lt() Function Example import operator# input two numbers x = int(input("Enter first number : ")) y = int(input("Enter second number: "))# printing the values print("x:",x, ", y:",y)# comparing if operator.lt(x,y):print(x, "is less than ", y) else:print(x, "is not less than ", y)Output:
輸出:
RUN 1: Enter first number : 10 Enter second number: 20 x: 10 , y: 20 10 is less than 20RUN 2: Enter first number : 20 Enter second number: 10 x: 20 , y: 10 20 is not less than 10翻譯自: https://www.includehelp.com/python/operator-lt-function-with-examples.aspx
總結(jié)
以上是生活随笔為你收集整理的Python operator.lt()函数与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++stl和std_std :: ro
- 下一篇: 紫外线的形式是什么?