Home  >  Article  >  Backend Development  >  Are python collections mutable types?

Are python collections mutable types?

anonymity
anonymityOriginal
2019-06-14 15:49:167094browse

Python variables can be divided into two types

Immutable types (numbers, strings, tuples, immutable collections)

Variable types (lists, dictionaries, Variable collection)

Are python collections mutable types?

#The variables declared by python exist in the form of objects and exist in the fixed memory of the machine.

can be understood as a pointer to an object with the variable name

Collection

We often use it to perform deduplication and relational operations, Collections are unordered.

s = {1,'d','34','1',1}
print(s,type(s),id(s))
s.add('djx')
print(s,type(s),id(s))
result:
{&#39;d&#39;, 1, &#39;34&#39;, &#39;1&#39;} <class &#39;set&#39;> 870405285032
{1, &#39;34&#39;, &#39;djx&#39;, &#39;1&#39;, &#39;d&#39;} <class &#39;set&#39;> 870405285032

We can find that although the collection data changes, the memory address does not change, so the collection is a variable data type.

The above is the detailed content of Are python collections mutable 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