Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9
List in Python are similar to arrays in other programming languages. In order to create it, you write square brackets or a built-in list tool. The list consists of elements such as strings, numbers, objects, and mixture types. List functions: 1. combine two lists together (extend) or add a list to the list (append) 2. sort the list (sort) and much more. A Tuple consists of a series of values ​​separated by commas, enclosed in parentheses or without them. Functions of the tuple: 1. You can also count the number of certain elements (count) 2. Also it is possible to return a certain value of an element (index) and on it almost everything( But there is a feature: 1. That the cortege is faster than the list! 2. It is safer to store data in the tuple! 3. The tuple weighs less than the list! Therefore, when there is a choice between using items simply and without unnecessary hassle with all the privileges, then use the list. If it's worth a question about safety and speed, you know who to choose)
26th Sep 2018, 11:44 PM
Amir
Amir - avatar
+ 9
a secondary advantage is, that tuples might serve as keys for dictionaries. lists are not allowed. This is the consequence of mutable/immutable
27th Sep 2018, 12:54 PM
Oma Falk
Oma Falk - avatar
+ 6
I made the same question, here you will see some examples that people told me in that moment. I hope it helps you. https://www.sololearn.com/discuss/1518680/?ref=app
26th Sep 2018, 9:54 PM
Enzo Falcon
Enzo Falcon - avatar
+ 4
The main advantage of lists is that they are mutable objects and easy to alter when required, whereas tuples must be over-written in place. The only advantage I can see is that, since tuples are immutable, if there is one tuple of other immutable objects, then anything that is the same as that item will be pointed to the same object. Any attempt to alter it creates a new object, and if another item is linked to it then the original item remains as before. This will come into play if memory is a significant issue, which in small-scale code is not an issue. However, a few million tuples consisting of pairs of booleans or even small (-ish) integers (such as co-ordinates) will take up a lot less memory than equivalent lists or other mutable types. There is a second issue with lists, a simple assignment to an existing list will create an alias and any change to the new assignment will alter the original list as well. However, there are plenty of easy ways to copy lists so it is a minor issue, almost a design feature.
27th Sep 2018, 12:20 AM
Jonathan Shiell
+ 2
mutable and immutable is the only difference I know!
27th Sep 2018, 10:49 AM
Arjit Gupta
Arjit Gupta - avatar
+ 2
another great use for a tuple is picking up unknown amount of arguments to a function. I wrote C's printf function for Python that uses tuples to handle the unknown amount of things to format and print printf.py https://code.sololearn.com/cH7fs55oWP8G/?ref=app
28th Sep 2018, 1:18 PM
Rick Shiffman
Rick Shiffman - avatar
+ 1
Tuples are faster than lists!
28th Sep 2018, 2:55 PM
Pedro Tortello
Pedro Tortello - avatar
0
tuples use how key in dictionary
27th Sep 2018, 8:01 PM
Andrey7 Pasternak
Andrey7 Pasternak - avatar
0
jjjjiklll to p0aaà
28th Sep 2018, 1:39 PM
Rohini Sarade
Rohini Sarade - avatar
0
Tuples are fixed size in nature whereas lists are dynamic. In other words, a tuple is immutable whereas a list is mutable. You can't add elements to a tuple. Tuples have no append or extend method. You can't remove elements from a tuple. Tuples have no remove or pop method. You can find elements in a tuple, since this doesn’t change the tuple. You can also use the in operator to check if an element exists in the tuple. More: http://net-informations.com/JUMP_LINK__&&__python__&&__JUMP_LINK/iq/tup.htm
29th Jan 2020, 6:39 AM
rahul kumar
rahul kumar - avatar
0
List is recorrected or U can add the string or delete but U cannot do same in tuple
27th Feb 2020, 6:59 PM
Twinkal meshram
Twinkal meshram - avatar
0
tuples are way faster then lists trust me or look it up in your search engine
22nd Jun 2020, 9:32 PM
Shreyaansh
Shreyaansh - avatar
0
you can not change a tuple but list you can
24th Jul 2020, 7:47 PM
Leonrado
Leonrado - avatar
0
really dose not matter
24th Jul 2020, 10:13 PM
Shreyaansh
Shreyaansh - avatar