Code -
Solution and Explanation:
The variable fruits seems to be defined as a set, but you are trying to use the clear() method on it, which is applicable to dictionaries, not sets. If you want to clear a set, you can use the clear() method directly on the set. Here's the corrected code:
fruits = {'Kiwi', 'Jack Fruit', 'Lichi'}
fruits.clear()
print(fruits)
This will output an empty set:
set()
If you intended fruits to be a dictionary, you should define it using key-value pairs, like this:
fruits = {'kiwi': 1, 'jackfruit': 2, 'lichi': 3}
fruits.clear()
print(fruits)
This will output an empty dictionary:
{}
0 Comments:
Post a Comment