Why is the output of the code:(0,2,2) instead of ((0,),(2,),(2,)) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is the output of the code:(0,2,2) instead of ((0,),(2,),(2,))

https://code.sololearn.com/c4lcX1K2LD6x/?ref=app

14th May 2020, 1:56 AM
Alen Antony
Alen Antony - avatar
7 Answers
+ 5
Check out the output of the 4th line. You will understand yourself.. https://code.sololearn.com/cjWNm1tAJWE8/?ref=app
14th May 2020, 2:07 AM
Ayush Dwivedi
Ayush Dwivedi - avatar
+ 2
You can build nested tuples, but not with the multiplication operator. t1 = 0, 1 print(t1) t2 = t1, t1 print(t2)
14th May 2020, 2:25 AM
Tibor Santa
Tibor Santa - avatar
+ 2
Here is how you can achieve the output you asked: https://code.sololearn.com/cQG9m1bdWDTO/?ref=app
14th May 2020, 2:29 AM
Tibor Santa
Tibor Santa - avatar
+ 2
mutible is tuple
14th May 2020, 2:39 AM
💡Arno Gevorgyan 🐍
💡Arno Gevorgyan 🐍 - avatar
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 your code works too. The multiplication of list and tuple works consistently in Python. print((1,) * 5) # tuple of 5 print([1] * 5) # list of 5
14th May 2020, 2:42 AM
Tibor Santa
Tibor Santa - avatar
0
Why can't we form a nested tuple , like nested lists?
14th May 2020, 2:10 AM
Alen Antony
Alen Antony - avatar
0
Well that's my question?
14th May 2020, 2:21 AM
Alen Antony
Alen Antony - avatar