0% found this document useful (0 votes)
3 views

python6

The document provides an overview of relational operators in Python, including their definitions and examples of usage. It highlights common mistakes, such as incorrect syntax and the importance of case sensitivity in comparisons. Additionally, it explains how to compare numbers, integers, floats, and strings, emphasizing that Python treats different data types distinctly.

Uploaded by

Prachi More
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

python6

The document provides an overview of relational operators in Python, including their definitions and examples of usage. It highlights common mistakes, such as incorrect syntax and the importance of case sensitivity in comparisons. Additionally, it explains how to compare numbers, integers, floats, and strings, emphasizing that Python treats different data types distinctly.

Uploaded by

Prachi More
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

7/27/24, 8:58 PM Revolutionizing the Job Market | NxtWave

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=36b50c7e-806a-4834-859f-1c031bdf9942&s_id=6e7a0638… 1/5
7/27/24, 8:58 PM Revolutionizing the Job Market | NxtWave

Relational Operators
Relational Operators are used to compare values.
Gives

True or False as the result of a comparison.

These are different relational operators

Operator Name

> Is greater than

< Is less than

== Is equal to

<= Is less than or equal to

>= Is greater than or equal to

!= Is not equal to

Code
PYTHON

1 print(5 < 10)


2 print(2 > 1)

Output

True
True

Possible Mistakes

Mistake - 1

Code
PYTHON

1 print(3 = 3)

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=36b50c7e-806a-4834-859f-1c031bdf9942&s_id=6e7a0638… 2/5
7/27/24, 8:58 PM Revolutionizing the Job Market | NxtWave

Output

SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

Mistake - 2

Code
PYTHON

1 print(2 < = 3)

Output

SyntaxError: invalid syntax

Space between relational operators

== , >= , <= , != is not valid in Python.

Comparing Numbers

Code
PYTHON

1 print(2 <= 3)
2 print(2.53 >= 2.55)

Output

True
False

Comparing Integers and Floats

Code

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=36b50c7e-806a-4834-859f-1c031bdf9942&s_id=6e7a0638… 3/5
7/27/24, 8:58 PM Revolutionizing the Job Market | NxtWave

PYTHON

1 print(12 == 12.0)
2 print(12 == 12.1)

Output

True
False

Comparing Strings

Code
PYTHON

1 print("ABC" == "ABC")
2 print("CBA" != "ABC")

Output

True
True

Case Sensitive

Code
PYTHON

1 print("ABC" == "abc")

Output

False

Python is case sensitive.


It means

X (Capital letter) and x (small letter) are not the same in Python.

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=36b50c7e-806a-4834-859f-1c031bdf9942&s_id=6e7a0638… 4/5
7/27/24, 8:58 PM Revolutionizing the Job Market | NxtWave

Strings and Equality Operator


Code
PYTHON

1 print(True == "True")
2 print(123 == "123")
3 print(1.1 == "1.1")

Output

False
False
False

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=36b50c7e-806a-4834-859f-1c031bdf9942&s_id=6e7a0638… 5/5

You might also like