Tools, FAQ, Tutorials:
'list' Values are Objects
Are "list" values objects in Python?
✍: FYIcenter.com
Yes, "list" values are objects in Python.
In fact, all data values in Python are objects.
In Python, "list" is defined as an object class with the following interesting properties, constructors, and methods:
list.__doc__ - Property holding a short description of "list" objects.
list.__new__() - Constructor returning a "list" object. It can be invoked as list(). For example:
>>> list.__new__(list)
[]
>>> list()
[]
>>> list(("Age", 25))
['Age', 25]
>>> list(["Age", 25])
['Age', 25]
>>> list("FYIcenter.com")
['F', 'Y', 'I', 'c', 'e', 'n', 't', 'e', 'r', '.', 'c', 'o', 'm']
list.__getitem__() - Instance method for the [] operation, returning item of the list at the given position. For example:
>>> ['Age', 25].__getitem__(1) 25 >>> ['Age', 25][1] 25 >>> (['Age', 25])[1] 25
list.__len__() - Instance method returning the number of items in the list. It can be invoked as len(list). For example:
>>> ['Age', 25].__len__() 2 >>> len(['Age', 25]) 2
list.__sizeof__() - Instance method returning the size of the list in memory, in bytes. For example:
>>> ['Age', 25].__sizeof__() 28 >>> [].__sizeof__() 20
list.append() - Instance method appending a new value to the end of the list. For example:
>>> a = ['Age', 25] >>> a.append(["Name","Joe"]) >>> a ['Age', 25, ['Name', 'Joe']] >>>
You can use the dir(list) function to see all members of the "list" class:
>>> dir(list) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__' , '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__' , '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__r educe__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__' , '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort ']
2022-12-03, ∼2010🔥, 0💬
Popular Posts:
dev.FYIcenter.com is a Website for software developer looking for software development technologies,...
dev.FYIcenter.com is a Website for software developer looking for software development technologies,...
What is the "__init__()" class method? The "__init__()" class method is a special method that will b...
How to view API details on the Publisher Dashboard of an Azure API Management Service? You can follo...
How to use the "Ctrl-p Ctrl-q" sequence to detach console from the TTY terminal of container's runni...