please explain with some example.
Tell some important characteristics also.
1 2328 bvdet 2,851
Expert Mod 2GB
A list (notice the square brackets): - >>> alist = [1,2,3,4]
-
>>> dir(alist)
-
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
A tuple (notice the parentheses): - >>> atuple = (1,2,3)
-
>>> dir(atuple)
-
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__str__']
The biggest difference is a list is mutable and a tuple is immutable. A tuple can be used as a dictionary key and a list cannot. They also have different methods.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pierre Fortin |
last post by:
Hi,
Is the following a reasonable generic approach for converting python
returned tuples/lists into dicts...? I'm not advocating library functions
also return dicts (I'd probably spend more...
|
by: diadia |
last post by:
string s = "hello";
const char *p = s.begin();
cout << p << endl; // print hello
s = "";
char *p2= s.begin();
cout << p2 << endl; // print hello why?????
|
by: daniel |
last post by:
is there any typical usage that shows their difference?
thanks
daniel
|
by: bhushanbagul |
last post by:
Hi All
Please let me know exactly what difference i and g makes in oracle version i.e. when we say oracle 10g or oracle 11i
Thanks
Bhushan
|
by: beginner |
last post by:
Hi,
I am wondering how do I 'flatten' a list or a tuple? For example, I'd
like to transform or ] to .
Another question is how do I pass a tuple or list of all the
aurgements of a function to...
|
by: bruce |
last post by:
hi guys/gals...
got a basic question that i can't get my hands around.
i'm trying to programatically create/use a list/tuple (or whatever the right
phrase in pyton is!!)
basically,...
|
by: bruce |
last post by:
Hi Fredrik...
so, this still doesn't get me an array called 'cat', or 'dog'
or do i somehow use stuff to add/extract the vals...???
thanks
-----Original Message-----
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |