+ 1

Why the output of this code is 4 ? Please explain

Nums= set ([1,1,2,3,3,3,4]) Print (Len(nums))

8th Feb 2019, 10:03 PM
H.code
2 Antworten
+ 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.
8th Feb 2019, 10:22 PM
Hazmat
Hazmat - avatar
+ 3
A set has no duplicate element.
8th Feb 2019, 10:17 PM
Zen
Zen - avatar