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

Are python collections mutable types?

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

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:
{'d', 1, '34', '1'}  870405285032
{1, '34', 'djx', '1', 'd'}  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