+ 2

SOLVED Python. What's the difference between () and []

x = (1,2) y = [1,2] print(x[0]+x[1]) print(y[0]+y[1]) # first n second output is 3 is x array or y is array ? (list or array) I've learnt c++ and this is a confusing

16th Nov 2018, 2:42 PM
Muhamad Fathi Zuhaili
Muhamad Fathi Zuhaili - avatar
3 Antworten
+ 3
If i remember correctly () are tuples [] are lists https://www.sololearn.com/discuss/1521094/?ref=app
16th Nov 2018, 3:01 PM
Taste
Taste - avatar
+ 3
Here x is tuple.which is immutable and y is list which is similar to array i say similar not equal means in list you can also hold a different type of data types together but if we talk about array this is not possible in array.and y which is here list also a mutable data type. Also check this link for more information. https://www.pythoncentral.io/JUMP_LINK__&&__python__&&__JUMP_LINK-lists-and-tuples/
16th Nov 2018, 4:43 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
Following Taste 's post, tuples are inmutable, while lists are mutable.
16th Nov 2018, 3:22 PM
Bebida Roja
Bebida Roja - avatar