+ 1
Why the output of this code is 4 ? Please explain
Nums= set ([1,1,2,3,3,3,4]) Print (Len(nums))
2 Answers
+ 1
"setâ does not set the same item more than once. so for example:
items = set([âonceâ, âonceâ])
if I print âitemsâ it will only show:
{âonceâ}.
So your set is setting 1:1, 1:2, 1:3 and 1:4. the length of 4 is 4 so you are seeing it print 4.
+ 3
A set has no duplicate element.