Home  >  Article  >  Backend Development  >  The difference between python data types

The difference between python data types

(*-*)浩
(*-*)浩Original
2019-08-02 13:58:263015browse

The difference between python data types

The difference between python data types

The difference between set collection and dict dictionary(recommended learning:Python video tutorial)

The only difference: set has no corresponding value

Both are variable types, that is, not hashable

The internal elements of both are immutable types, which can be hashed

Both have no indexes, slicing and operations based on indexes are not possible

set collection and list Differences between lists

Same points

–Both are variable types

Differences

– The set collection is unordered and has unique elements

– The set collection can only obtain elements through a for loop, otherwise it is unordered and has no index

– The list is ordered and the elements are not unique, and can be sliced ​​according to the index

– The list is a dynamic sequence table with a separated structure (the reason for the index)

– The set collection is mainly used for test data and data intersection, union, difference and other types of deduplication operations.

– The essential difference between the set collection and the dict dictionary is the same.

list list Differences from dict dictionary

Same points:

Variable type

Iterable

Different Point:

The key of the dict dictionary must be an immutable object

The dict dictionary requires more storage space than the list list

The query efficiency of the dictionary is much higher than that of the list

The difference between tuples and lists

The difference:

The tuple object is immutable after it is created

How to create objects: list = ["Element"] tuple=("Element",)

Same points:

Iterable

tuple tuple, string, number

Immutable type (hashable), elements cannot be changed

Tuples can contain mutable types

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of The difference between python data types. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to call python in c#Next article:How to call python in c#