pyhton基础学习《元组字典的常用操作》
Posted wings-xu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pyhton基础学习《元组字典的常用操作》相关的知识,希望对你有一定的参考价值。
一、元组
(1)元组的创建
tu = (11,22,33,)或者tu = tupel((11,22,33))
(2)元组常用的操作
def count(self, value): # real signature unknown; restored from __doc__
""" T.count(value) -> integer -- return number of occurrences of value """
#计数
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.
"""
#索引
二、字典
(1)字典的创建
dic = {"k1":"v1","k2":"v2"} 或者 dic = dict(k1 = "v1",k2 = "v2")
(2)字典的常用操作
def clear(self): # real signature unknown; restored from __doc__
""" D.clear() -> None. Remove all items from D. """
#清空字典
def copy(self): # real signature unknown; restored from __doc__
""" D.copy() -> a shallow copy of D """
#复制:浅的复制
def fromkeys(*args, **kwargs): # real signature unknown
""" Returns a new dict with keys from iterable and values equal to value. """
#序列设定KEY,附加值,生成新的字典
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. """
#当一个KEY不存在字典中时,返回一个默认直none或设置赋一个新的值,当KEY存在时,不生效
def items(self): # real signature unknown; restored from __doc__
""" D.items() -> a set-like object providing a view on D‘s items """
#输出字典中的对象
def keys(self): # real signature unknown; restored from __doc__
""" D.keys() -> a set-like object providing a view on D‘s keys """
#输出字典中的KEY
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
"""
#指定删除一个KEY
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.
"""
#随机删除一个KEY,并反回删除的KEY
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 """
#给KEY设默认值
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]
"""
#更新字典
def values(self): # real signature unknown; restored from __doc__
""" D.values() -> an object providing a view on D‘s values """
#输出字典KEY的值
以上是关于pyhton基础学习《元组字典的常用操作》的主要内容,如果未能解决你的问题,请参考以下文章