DEV Community

loading...

What will be the result of following code?

lakshyatyagi24 profile image Lakshya Tyagi ・1 min read
>>> a = {1, 2, {3, 4}}
>>> len(a)
Enter fullscreen mode Exit fullscreen mode
  1. 3
  2. 4
  3. error

Write your answer in comment with explaination

Discussion (5)

pic
Editor guide
Collapse
qm3ster profile image
Mihail Malo

Bad order of answers. "3" is ambiguous.

  1. error
  2. 4
  3. 3

would be much better

Collapse
lakshyatyagi24 profile image
Collapse
promikecoder2020 profile image
ProMikeCoder2020 • Edited

A is parsed as set with three values: two integers and another set. Thus it gives a Len of 3

Collapse
sambhavjindalgithub profile image
Collapse
dibyadarshan8 profile image