Sunday 12 March 2023

Logical Operators

Logical operators 

The Logical operators that we can perform in python are:
  1. Logical AND (&&)
  2. Logical OR (||)
  3. Logical NOT (!)

Logical AND (&&)

The logical AND operator returns True if both the statements are True else returns False.


a=55
if(a&gt50 and a&lt100):
    print("a lies between 50 and 100")
Output
a lies between 50 and 100

Logical OR (||)

The logical OR operator returns true if any one of the statements are true and false if both the statements are false.
a=50
if(a&gt0 or a&lt0):
    print("a is either positive or negative")
else:
    print("a is zero")
Output
a is either positive or negative

Logical NOT (!)

Logical NOT operator is performed only on single expression. It converts True value to False and False value to True.


a=0     
if(a!=0):
    print("a is either positive or negative")
else:
    print("a is zero")
Output
a is zero

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top