Step-by-step Execution:
Define a Set:
- set1 is a set containing {10, 20, 30}.
Remove an Element:
- The .remove(20) method removes the element 20 from set1.
- However, remove() does not return anything; it modifies set1 in place.
- This means set2 gets assigned the return value of set1.remove(20), which is None.
Print the Result:
- Since set2 = None, the output will be:
- Since set2 = None, the output will be:
Final Output:
Key Learning:
- .remove() modifies the original set but returns None.
- If you assign set2 = set1.remove(x), set2 will always be None.
0 Comments:
Post a Comment