
TASK – The Botanical Garden and Rose Garden – Python SETS
1.Create a set named rose_garden containing different types of roses: "red rose", "white rose", "yellow rose". Print the same. CODE: rose_garden = {"red rose", "white rose", "yellow rose"} print(rose_garden) OUTPUT: {'red rose', 'white rose', 'yellow rose'} EXPLANATION: A set stores unique elements Order may vary 2.Add "pink rose" to the rose_garden set. Print the set to confirm the addition. CODE: rose_garden.add("pink rose") print(rose_garden) OUTPUT: {'red rose', 'white rose', 'yellow rose', 'pink rose'} EXPLANATION: -add() inserts a new element 3.Remove "yellow rose" from the rose_garden set using the remove() method. Print the set to verify the removal. CODE: rose_garden.remove("yellow rose") print(rose_garden) OUTPUT: {'red rose', 'white rose', 'pink rose'} EXPLANATION: remove() deletes element (error if not present) 4.Create another set botanical_garden with elements "sunflower", "tulip", and "red rose". Find the union of rose_garden and botanical_garden and print the result. CO
Continue reading on Dev.to Beginners
Opens in a new tab




