Home > Article > Backend Development > Are python collections mutable types?
Python variables can be divided into two types
Immutable types (numbers, strings, tuples, immutable collections)
Variable types (lists, dictionaries, Variable collection)
#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'} <class 'set'> 870405285032 {1, '34', 'djx', '1', 'd'} <class 'set'> 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!