+ 1
What is the problem in this code?
c=(6.0,4,7) c.append (3) c.append(8) print(c) I know that I must put these [ ] instead of these( ) but why? what is the different between them?
10 Answers
+ 5
[] make you create a list and like Vivek said lists are mutable, meaning they can be changed, values can be added or deleted from them...
() make you create a tuple and again, like Vivek said those are immutables, meaning they cannot be changed, values cannot be added or deleted from them.
So that is why you should have used [] if you knew you would be adding values to it
+ 5
Yes. () to create or declare tuples and [] to declare lists
+ 4
Tuples are immutable; they can't be changed. So you need to convert it to a list, append values and then back to a tuple again.
+ 3
Look at this code. First part with list works and second part with tuple not.
https://code.sololearn.com/cmpZISauuRrS/?ref=app
+ 3
And look at the answers in this discussion. They answer your question about the benefits of using tuples sometimes
https://www.sololearn.com/Discuss/36164/?ref=app
+ 2
and tubles is constant so I cannot add any addition numbres to them
but lists isnot constant so I can add numres ti them
and that is why the code didnot work??
+ 2
Yes again
+ 1
so we use ( ) in tubles
and [ ] in lists?
+ 1
Ok cyk thank uđ
0
so what is the benifet of these ( ) tuples
when I cannot add any numbres to them?