300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Python数据类型详解(四)字典:dict

Python数据类型详解(四)字典:dict

时间:2018-08-27 07:54:22

相关推荐

Python数据类型详解(四)字典:dict

后端开发|Python教程

Python数据类型,字典,dict

后端开发-Python教程

一.基本数据类型

saas源码 哪里可以买,安装ubuntu分区教程,访问阿里云tomcat地址,爬虫库安装,php教程阿里云学习,熟练seolzw

整数:int

字符串:str(注:\t等于一个tab键)

布尔值: bool

列表:list

列表用[]

元祖:tuple

元祖用

字典:dict

手机靓号商城源码,vscode的扩展名,ubuntu远程策略,tomcat部署不生效,爬虫 加密视频,php 获取微信用户信息,下沙seo排名优化,门户网站jsp源代码,php 社交网站模板源码lzw

注:所有的数据类型都存在想对应的类列里,元祖和列表功能一样,列表可以修改,元祖不能修改。

jquery手风琴源码,vscode调试java,ubuntu截图保存到哪里,tomcat容器限流,sqlite js操作类,php报表插件 打印,web前端框架搭建视频,爬虫温控器调节,php还是asp,杭州seo广告,漏洞提交网站源码,手机开发网页的软件,杰奇模板源码,cpa电影程序lzw

二.字典所有数据类型:

常用操作:

索引、新增、删除、键、值、键值对、循环、长度

class dict(object): """ dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping objects (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 Ds items """ pass def keys(self): # real signature unknown; restored from __doc__ """ D.keys() -> a set-like object providing a view on Ds 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 Ds 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 objects(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 pairsin 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<=value. """ pass def __lt__(self, *args, **kwargs): # real signature unknown """ Return self size of D in memory, in bytes """ pass __hash__ = None

三.所有字典数据类型举例

user_info = { 0 :"zhangyanlin", "age" :"18", 2 :"pythoner"}#获取所有的keyprint(user_info.keys()) #获取所有的valuesprint(user_info.values()) #获取所有的key和valuesprint(user_info.items()) clear清除所有的内容user_info.clear()print(user_info) #get 根据key获取值,如果key不存在,可以指定一个默认值val = user_info.get(age)print(val)#update批量更新test = { a:111, :222}user_info.update(test)print(user_info)

四.索引

#如果没有key,会报错user_info = { "name" :zhangyanlin, "age" :18, "job" :pythoner}print(user_info[ ame])

五.for循环

#循环user_info = { 0 :"zhangyanlin", "age" :"18", 2 :"pythoner"}for i in user_info: print(i) #循环输出所有的键入值for k,v in user_info.items(): print(k) print(v)

以上就是本文的全部内容了,希望对大家熟练掌握Python数据结构能够有所帮助。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。