+ 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 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.
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