Python 3 Script to Find Difference Between Two Sets Using (-) Operator & Difference() Method

Python 3 Script to Find Difference Between Two Sets Using (-) Operator & difference() Method

A = {'a', 'b', 'c', 'd'}
B = {'c', 'f', 'g'}
 
# Equivalent to A-B
print(A.difference(B))
 
# Equivalent to B-A
print(B.difference(A))

A = {'a', 'b', 'c', 'd'}
B = {'c', 'f', 'g'}
 
print(A-B)
 
print(B-A)

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment