Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

# Relational Operators in Python

Last Updated on January 31, 2023 by Prepbytes

In this article, we will discuss the relational operators in python, types of relational operators in python, Some examples of relational operators in python, code implementation and its explanation, and one quiz on the relational operator.

## What are Relational Operators in Python

Relational operators in python are the mathematical symbol, used for comparing the operand values, they return a boolean value(either True or False) according to the condition. They are also known as Comparison operators. mainly they are of 6 types.

``````>
<
==
!=
>=
<=``````

Types of Relational Operators in Python

Operator         Description       Syntax
> Greater than: return true if the value of the left operand is greater than the right a>b
< Less than return true if the value of the left operand is lesser than the right a< b
== Equal: return true if both operands are equal a==b
!= Not equal to return true if the operands are not equal a!=b
>= Greater than equal to return true if the value of the left operand is greater than or equal to the right a>=b
<= less than equal to: return true if the value of the left operand is less than or equal to the right a<=b

### Example 1: Greater than(>)

Syntax:

``a>b``

Code:

``````a=20
b=13
#on output screen
print(a>b)``````

Output:

``True``

Explanation
In the above python program we have two variables a and b . the value of is 20 and the value of b is 13. So as we discuss earlier relational operator gives a boolean result, So here we use ‘>’ greater than (relational operator) it returns true if the left operand is greater than the right operand, and we know 20 is greater than 13, so in the output screen, we have [True] as a result.

### Example 2: Less than(<)

Syntax:

`` a``
``` Code: a=20 b=13 #on output screen print(a Output: False Explanation In the above python program we have two variables a and b . the value of is 20 and the value of b is 13. So as we discuss earlier relational operator gives a boolean result, So here we use ‘<’ less than (relational operator) it returns true if the left operand is less than the right operand, and we know 20 is not less than 13, so in the output screen, we have [False] as a result. Example 3: Equal to(==) Syntax: a==b Code: a=20 b=13 #on output screen print(a==b) Output: False Explanation In the above python program we have two variables a and b . the value of is 20 and the value of b is 13. So as we discuss earlier relational operator gives a boolean result, So here we use ‘==’ equal to (relational operator) it returns true if the left operand is equal to the right operand, and we know 20 is not equal to 13, so in the output screen, we have [False] as a result. Example 4: Not equal to (!=) Syntax: a!=b Code: a=20 b=13 #on output screen print(a!=b) Output: True Explanation In the above python program we have two variables a and b . the value of is 20 and the value of b is 13. So as we discuss earlier relational operator gives a boolean result, So here we use ‘==’ not equal to (relational operator) it returns true if the left operand is not equal to the right operand, and we know 20 is not equal to 13, so in the output screen, we have [True] as a result. Example 5: Greater than equal to (>=) Syntax: a>=b Code: a=20 b=13 #on output screen print(a>=b) Output: True Explanation In the above python program we have two variables a and b . the value of is 20 and the value of b is 13. So as we discuss earlier relational operator gives a boolean result, So here we use ‘>=’ greater than or equal to (relational operator) it returns true if the left operand is greater than or equal to the right operand, and we know 20 is greater than 13, so in the output screen, we have [True] as a result. Example 6: Less than equal to(<=) Syntax: a<=b Code: a=20 b=13 #on output screen print(a<=b) Output: False Explanation In the above python program we have two variables a and b . the value of is 20 and the value of b is 13. So as we discuss earlier relational operator gives a boolean result, So here we use ‘<=’ less than equal to (relational operator) it returns true if the left operand is less than or equal to the right operand, and we know 20 is not less than or equal to 13, so in the output screen, we have [False] as a result. Quiz: Which of the following is not a relational operator? = <= != ! Option D is right ans. ! is a logical operator. Logical operators !,|,||,&,&& Relational operator >,<,<=,>=,==,!= Summary A relational operator in Python is a symbol or keyword used to compare two values and determine the relationship between them. The most commonly used relational operators in Python are < (less than) > (greater than) <= (less than or equal to) >= (greater than or equal to) == (equal to) != (not equal to) These operators can be used in conditional statements and loops to control the flow of a program. For example, the following code uses the < operator to check if a variable x is less than 10 ```
``` ```
``` ```
``` ```
``` Post navigation Previous Previous post: Link State Routing AlgorithmNext Next post: Python Built-in Functions Leave a Reply Your email address will not be published. Required fields are marked *Comment * Name * Email * Website Save my name, email, and website in this browser for the next time I comment. ```
``` ```
``` Search for: Pages ALGORITHMS ARRAY BACKTRACKING C PROGRAMMING LANGUAGE C++ PROGRAMMING LANGUAGE CAPGEMINI CIRCULAR LINKED LIST COMPANY PLACEMENT PROCEDURE COMPETITIVE CODING COMPUTATIONAL GEOMETRY CSE SUBJECTS DATA STRUCTURE DOUBLY LINKED LIST DYNAMIC PROGRAMMING GAME THEORY GRAPHS GREEDY ALGORITHM HASHING HEAP INTERVIEW PREPARATION INTERVIEW TIPS JAVA PROGRAMMING LANGUAGE JAVASCRIPT PROGRAMMING LANGUAGE Languages LINKED LIST LINKED LIST USING C MATHEMATICS OPERATING SYSTEM POINTERS PYTHON PROGRAMMING LANGUAGE QUEUE RECURSION SEARCHING SEGMENT TREE SORTING STACK STRING TREES Recent Articles 1 September 9, 2024 VLAN ACL (VACL) in Computer Networks 2 September 9, 2024 Inter-VLAN Routing Using a Layer 3 Switch 3 September 8, 2024 Access and Trunk Ports in Computer Networks 4 September 8, 2024 Role-Based Access Control (RBAC) in Computer Networks 5 September 6, 2024 Display Processor in Computer Graphics 6 September 6, 2024 Methods for Text Clipping in Computer Graphics ```
``` Close Search for: Menu Language C C++ Java Javascript Python Data Structure Array Graphs Heap Linked List Segment Tree Stack Trees Queue Algorithm Backtracking Dynamic Programming Greedy Algorithm RECURSION Searching Sorting CSE Subjects Operating System Company Placement Interview Interview Tips General Interview Questions Algorithms Data Structure Languages Other Topics Competitive Data Structure Array Graph Heap Segment Tree Stack Queue Tree Tries Algorithm Backtracking Dynamic Programming Greedy Algorithm Searching Sorting Other Topics Computational Geometry Game Theory Maths Pointers Recursion String Others Computational Geometry Game Theory Hashing Maths Pointers Recursion String Related Post Python List Functions & Python List Methods October 30, 2023 Python Interview Questions September 18, 2023 Namespaces and Scope in Python August 30, 2023 What is the Difference Between append and extend in Python? August 10, 2023 Python Program to Check For the Perfect Square July 4, 2023 Python Program To Find The Sum Of First N Natural Numbers July 4, 2023 FOLLOW US CONTACT US +91-7969002111 contact@prepbytes.com QUICK LINKS Interview NotesMock TestsPlacement ProgrammeCoding CoursesMock InterviewAbout UsBlog ```
``` /** * Core styles: block-supports */ /* <![CDATA[ */ var utils_data = {"serverUrl":"https:\/\/server.prepbytes.com"}; /* ]]> */ /* <![CDATA[ */ var login_data = {"serverUrl":"https:\/\/server.prepbytes.com"}; var webinar_data = {"webinarUrl":"https:\/\/webinar.prepbytes.com\/"}; /* ]]> */ /* <![CDATA[ */ var login_data = {"serverUrl":"https:\/\/server.prepbytes.com"}; /* ]]> */ /* <![CDATA[ */ var infinity_news_custom_script = {"daymod":"Light Mode","nightmod":"Dark Mode"}; /* ]]> */ /* <![CDATA[ */ var infinity_news_ajax = {"ajax_url":"https:\/\/blog.prepbytes.com\/wp-admin\/admin-ajax.php","loadmore":"Load More","nomore":"No More Posts","loading":"Loading..."}; /* ]]> */ !function(e,n){if("undefined"!=typeof EnlighterJS){var o={"selectors":{"block":"pre.EnlighterJSRAW","inline":"code.EnlighterJSRAW"},"options":{"indent":4,"ampersandCleanup":true,"linehover":true,"rawcodeDbclick":false,"textOverflow":"break","linenumbers":false,"theme":"enlighter","language":"generic","retainCssClasses":false,"collapse":false,"toolbarOuter":"","toolbarTop":"{BTN_RAW}{BTN_COPY}{BTN_WINDOW}{BTN_WEBSITE}","toolbarBottom":""}};(e.EnlighterJSINIT=function(){EnlighterJS.init(o.selectors.block,o.selectors.inline,o.options)})()}else{(n&&(n.error||n.log)||function(){})("Error: EnlighterJS resources not loaded yet!")}}(window,console); ```