Back to articles
Botanical garden
How-To

Botanical garden

via Dev.to TutorialJAYA SRI J

Create and print a set Concept: A set stores unique elements (no duplicates). rose_garden = { " red rose " , " white rose " , " yellow rose " } print ( rose_garden ) Explanation: Sets automatically avoid duplicates and are unordered. 2.Add an element Concept: Use add() to insert a new item. rose_garden . add ( " pink rose " ) print ( rose_garden ) Explanation: Adds a new element to the set. 3.Remove an element Concept: Use remove(). rose_garden . remove ( " yellow rose " ) print ( rose_garden ) Explanation: Removes the specified element. If not present, it causes an error. 4.Union of two sets Concept: Combine all elements. botanical_garden = { " sunflower " , " tulip " , " red rose " } print ( rose_garden . union ( botanical_garden )) Explanation: Union includes all unique elements from both sets. 5.Intersection of sets Concept: Find common elements. print ( rose_garden . intersection ( botanical_garden )) Explanation: Returns only elements present in both sets. 6.Difference of sets Co

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
0 views

Related Articles