Exercise: Chapter 4 (1-2)

1.

Just showing the help documents.

>>> help(str)
>>> help(list)
>>> help(tuple)

2.

Just compare the two help documents.

Tuple:
Help on class tuple in module __builtin__:

class tuple(object)
| tuple() -> empty tuple
| tuple(iterable) -> tuple initialized from iterable's items
|
| If the argument is a tuple, the return value is the same object.
|
| Methods defined here:
|
| __add__(...)
| x.__add__(y) x+y
|
| __contains__(...)
| x.__contains__(y) y in x
|
| __eq__(...)
| x.__eq__(y) x==y
|
| __ge__(...)
| x.__ge__(y) x>=y
|
| __getattribute__(...)

| x.__getattribute__('name') x.name
|
| __getitem__(...)
| x.__getitem__(y) x[y]
|
| __getnewargs__(...)
|
| __getslice__(...)
| x.__getslice__(i, j) x[i:j]
|
| Use of negative indices is not supported.
|
| __gt__(...)
| x.__gt__(y) x>y
|
| __hash__(...)
| x.__hash__() hash(x)
|
| __iter__(...)
| x.__iter__() iter(x)
|
| __le__(...)
| x.__le__(y) x<=y
| __len__(...)
| x.__len__() len(x)
|
| __lt__(...)
| x.__lt__(y) x<y
|
| __mul__(...)
| x.__mul__(n) x*n
|
| __ne__(...)
| x.__ne__(y) x!=y
|
| __repr__(...)
| x.__repr__() repr(x)
|
| __rmul__(...)
| x.__rmul__(n) n*x
|
| __sizeof__(...)
| T.__sizeof__() -- size of T in memory, in bytes
|
| count(...)
| T.count(value) -> integer -- return number of occurrences of value
| index(...)
| T.index(value, [start, [stop]]) -> integer -- return first index of value.
| Raises ValueError if the value is not present.
|
|