Is, Not And In Operators in python

Spread the love
is, not and in operators in python
is, not and in operators in python

What is the purpose of is, not and in operators?

Not Operator:- It is logical operators and its meaning is true if operand is false.
Example :-

Code:-
a = True
b = False
print(not a)
print(not b)

Output:-
False
True

Is Operator:- It is identity operators and its meaning is true if the operands are identical.
Example :-

Code:-
a=[1,2,3,4]
b=[1,2,3,4]
c=[1,2,3,4,5]
d=a

if (a == b):
    print("True")
else:
    print("False")

if(a is b):
    print("True")
else:
    print("False")

if(a is c):
    print("True")
else:    
    print("False")

if (a is d):
    print("True")
else:    
    print("False")

e=[]
f=e
f=f+e
 
if (e is f):
    print("True")
else:    
    print("False")

Output:-
True
False
False
True
False

In Operator:- It is membership operators and its meaning is true if value/variable is found in the sequence i.e. the ‘in’ operator is used to check if a value exists in a sequence or not and it evaluates to true if it finds a variable in the specified sequence otherwise false.
Example :-

Code:-
a=[1,2,3,4]
b=[5,9,7,4,10,1]
for i in a:
    if i in b:
        print(i,"is present in both a and b i.e. true")
    else:
        print(i,"is not present in b i.e. false")

Output:-
1 is present in both a and b i.e. true
2 is not present in b i.e. false
3 is not present in b i.e. false
4 is present in both a and b i.e. true

Write a Python program to get a new string from a given string where “Is” has been added to the front. If the given string already begins with “Is” then return the string unchanged.

def solution(a):
q=0
if(a[0]==’I’):
if(a[1]==’s’):
q=1
print(“ans =”, a)
if(q!=1):
print(“ans = Is”+a.lower())

b=input(“Enter the word : “)
solution(b)

Summary :

In this article we saw What Is The Purpose Of Is Not And In Operators String so about this article you have any query then free to ask me

Intern name who share this Task: Shyamal Krishna Agrawal

I am Mr. Sachin pagar Embedded system engineer, the founder of Pythonslearning, a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

sachin Pagar

I am Mr. Sachin pagar Embedded system engineer, the founder of Pythonslearning, a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Leave a Reply