Home » Python

Python operator.lt() Function with Examples

Python operator.lt() Function: Here, we are going to learn about the operator.lt() function with examples in Python programming language.
Submitted by IncludeHelp, on April 14, 2020

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.

Module:

    import operator

Syntax:

    operator.lt(x,y)

Parameter(s):

  • x,y – values to be compared.

Return value:

The return type of this method is bool, it returns True if x is less than y, False, otherwise.

Example 1:

# Python operator.lt() Function Example

import operator

# integers
x = 10
y = 20

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()

# 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):  False

x: Apple , y: Banana
operator.lt(x,y):  True
operator.lt(y,x):  False
operator.lt(x,x):  False
operator.lt(y,y):  False

type((operator.lt(x,y)):  <class 'bool'>

Example 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  20

RUN 2:
Enter first number : 20
Enter second number: 10
x: 20 , y: 10
20 is not less than  10






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.