Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between python's dictionary and json?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "what is the difference between python's dictionary and json". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In python, json and dict are very similar, both of them are in the form of key-value, and json and dict can also be easily converted to each other through dumps and loads.

Define

In python, json and dict are very similar, both of them are in the form of key-value, and json and dict can also be easily converted to each other through dumps and loads. Since they are all in key-value format, why do they need to be converted?

Json (JavaScript Object Notation)

Json: is a data format that is a pure string. Can be parsed into dict or other forms of Python.

Dict: is a complete data structure, is an implementation of the Hash Table data structure, and is a set of packaged solutions from storage to extraction. It uses the built-in hash function to plan the storage location of key corresponding to value, so as to obtain O (1) data reading speed.

Comparison between json and dict

The key of json can only be a string, and the dict of python can be any hash object (hashtable type)

The key of json can be ordered and repeated; the key of dict cannot be repeated.

The value of json can only be a string, floating point, Boolean, or null, or an array or object made up of them.

Json any key has a default value undefined,dict has no default value

The json access method can be [] or. The value of in and of;dict can only be accessed by subscript.

Json strings force double quotation marks. Dict strings can be in single or double quotation marks.

Dict can be nested with only arrays in tuple,json.

Json:true 、 false 、 null

Python:True 、 False 、 None

Json Chinese must be unicode encoded, such as "\ u6211".

The type of json is a string, and the type of dictionary is a dictionary.

Hashtable

An object is hashtable when its hash value does not change during the declaration period and can be compared with other objects.

1. The basic types in python are all Hashtable, such as str, bytes, numeric type, tuple, etc.

2. User-defined types default to hashtable, because their hash value is the id () value.

3. Frozenset is always hashtable, because all of their projects are defined as hashtable

4. Tuple is hashtable only if all items in tuple are hashtable.

This is the end of the content of "what is the difference between python's Dictionary and json". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report