DEV Community

Lakshya Tyagi
Lakshya Tyagi

Posted on

What will be the result of following code?

>>> 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)

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
Lakshya Tyagi Author

Correct

Collapse
promikecoder2020 profile image
ProMikeCoder2020 • Edited on

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

Collapse
sambhavjindalgithub profile image
Sambhav-Jindal-github

3

Collapse
dibyadarshan8 profile image
Dibyadarshan Rath
  1. 3