Why is the output of the code:(0,2,2) instead of ((0,),(2,),(2,)) | SoloLearn: Learn to code for FREE!

0

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

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

5/14/2020 1:56:46 AM

Alen Antony

9 Answers

New Answer

+4

Check out the output of the 4th line. You will understand yourself.. https://code.sololearn.com/cjWNm1tAJWE8/?ref=app

+2

Alen Antony nyyc question & ofcourse we can form nested tuple like nested lists 👇👇 Here's your corrected code, check it f=((0,),) f=f+2*((2,),) print (f)

+2

You can build nested tuples, but not with the multiplication operator. t1 = 0, 1 print(t1) t2 = t1, t1 print(t2)

+2

Here is how you can achieve the output you asked: https://code.sololearn.com/cQG9m1bdWDTO/?ref=app

+2

Tibor Santa Why can't we do this with Multiplication operator Will you tell me? Plz check my code again ☝️☝️☝️☝️☝️☝️

+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

+1

mutible is tuple

0

Why can't we form a nested tuple , like nested lists?

0

Well that's my question?