python元组与字典的详细介绍

一、元组

1.元组的表达

(1,2,3,4)
(’olive’,123)
(”python”,)

创建元组:

a=tuple((1,2,3,))
b=(“python”,)

2.元组功能属性

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.
“””
def count(self, value): # real signature unknown; restored from __doc__
“”” t.count(value) -> integer — return number of occurrences of value “””
return 0
def index(self, value, start=none, stop=none): # real signature unknown; restored from __doc__
“””
t.index(value, [start, [stop]]) -> integer — return first index of value.
raises valueerror if the value is not present.
“””
return 0
def __add__(self, *args, **kwargs): # real signature unknown
“”” return self+value. “””
pass
def __contains__(self, *args, **kwargs): # real signature unknown
“”” return key in self. “””
pass
def __eq__(self, *args, **kwargs): # real signature unknown
“”” return self==value. “””
pass
def __getattribute__(self, *args, **kwargs): # real signature unknown
“”” return getattr(self, name). “””
pass
def __getitem__(self, *args, **kwargs): # real signature unknown
“”” return self[key]. “””
pass
def __getnewargs__(self, *args, **kwargs): # real signature unknown
pass
def __ge__(self, *args, **kwargs): # real signature unknown
“”” return self>=value. “””
pass
def __gt__(self, *args, **kwargs): # real signature unknown
“”” return self>value. “””
pass
def __hash__(self, *args, **kwargs): # real signature unknown
“”” return hash(self). “””
pass
def __init__(self, seq=()): # known special case of tuple.__init__
“””
tuple() -> empty tuple
tuple(iterable) -> tuple initialized from iterable’s items
if the argument is a tuple, the return value is the same object.
# (copied from class doc)
“””
pass
def __iter__(self, *args, **kwargs): # real signature unknown
“”” implement iter(self). “””
pass
def __len__(self, *args, **kwargs): # real signature unknown
“”” return len(self). “””
pass
def __le__(self, *args, **kwargs): # real signature unknown
“”” return self new empty dictionary
dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
dict(iterable) -> new dictionary initialized as if via:
d = {}
for k, v in iterable:
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. for example: dict(one=1, two=2)
“””
def clear(self): # real signature unknown; restored from __doc__
“”” d.clear() -> none. remove all items from d. “””
pass
def copy(self): # real signature unknown; restored from __doc__
“”” d.copy() -> a shallow copy of d “””
pass
@staticmethod # known case
def fromkeys(*args, **kwargs): # real signature unknown
“”” returns a new dict with keys from iterable and values equal to value. “””
pass
def get(self, k, d=none): # real signature unknown; restored from __doc__
“”” d.get(k[,d]) -> d[k] if k in d, else d. d defaults to none. “””
pass
def items(self): # real signature unknown; restored from __doc__
“”” d.items() -> a set-like object providing a view on d’s items “””
pass
def keys(self): # real signature unknown; restored from __doc__
“”” d.keys() -> a set-like object providing a view on d’s keys “””
pass
def pop(self, k, d=none): # real signature unknown; restored from __doc__
“””
d.pop(k[,d]) -> v, remove specified key and return the corresponding value.
if key is not found, d is returned if given, otherwise keyerror is raised
“””
pass
def popitem(self): # real signature unknown; restored from __doc__
“””
d.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise keyerror if d is empty.
“””
pass
def setdefault(self, k, d=none): # real signature unknown; restored from __doc__
“”” d.setdefault(k[,d]) -> d.get(k,d), also set d[k]=d if k not in d “””
pass
def update(self, e=none, **f): # known special case of dict.update
“””
d.update([e, ]**f) -> none. update d from dict/iterable e and f.
if e is present and has a .keys() method, then does: for k in e: d[k] = e[k]
if e is present and lacks a .keys() method, then does: for k, v in e: d[k] = v
in either case, this is followed by: for k in f: d[k] = f[k]
“””
pass
def values(self): # real signature unknown; restored from __doc__
“”” d.values() -> an object providing a view on d’s values “””
pass
def __contains__(self, *args, **kwargs): # real signature unknown
“”” true if d has a key k, else false. “””
pass
def __delitem__(self, *args, **kwargs): # real signature unknown
“”” delete self[key]. “””
pass
def __eq__(self, *args, **kwargs): # real signature unknown
“”” return self==value. “””
pass
def __getattribute__(self, *args, **kwargs): # real signature unknown
“”” return getattr(self, name). “””
pass
def __getitem__(self, y): # real signature unknown; restored from __doc__
“”” x.__getitem__(y) x[y] “””
pass
def __ge__(self, *args, **kwargs): # real signature unknown
“”” return self>=value. “””
pass
def __gt__(self, *args, **kwargs): # real signature unknown
“”” return self>value. “””
pass
def __init__(self, seq=none, **kwargs): # known special case of dict.__init__
“””
dict() -> new empty dictionary
dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
dict(iterable) -> new dictionary initialized as if via:
d = {}
for k, v in iterable:
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. for example: dict(one=1, two=2)
# (copied from class doc)
“””
pass
def __iter__(self, *args, **kwargs): # real signature unknown
“”” implement iter(self). “””
pass
def __len__(self, *args, **kwargs): # real signature unknown
“”” return len(self). “””
pass
def __le__(self, *args, **kwargs): # real signature unknown
“”” return self

Posted in 未分类

发表评论