Dictionary to (tuple or list)

Code:
a={“a”:“20”,“b”:“30”}
tuple(a[“a”])

output: ( ‘2’ , ‘0’)

why 20 split into 2 and 0.

Hey @Deepanshu19csu078, this is happening due to the fact that when you use tuple keyword, python by default splits a string into 2 elements. If you remove the word tuple, then the output will be 20 only. So when you mention tuple(a["a"]) , python expects to get a tuple but it just gets a 20 which it then splits into 2 and 0 to make a tuple of (‘2’ , ‘0’).
You can try this code as well :

a={"a":("20","10"),"b":"30"}
print(tuple(a["a"]))

Now since at a[“a”] there’s a tuple present , it will output the tuple itself like this without splitting anything :

('20', '10') 

I hope this clears your doubt ! :+1:
Happy Learning ! :slightly_smiling_face: