Home > Backend Development > Python Tutorial > Are python collections mutable types?

Are python collections mutable types?

anonymity
Release: 2019-06-14 15:49:16
Original
7144 people have browsed it

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template