mutable
Able to be changed in place after it is created, like most lists, arrays and objects in languages such as Python and JavaScript.
In more detail
Changing a mutable object through one name is visible through every other name that refers to it, which is the root of many aliasing surprises. Copying before changing, or using immutable values, avoids those surprises. In Python, mutable built-in types such as lists, dictionaries and sets are not hashable, so they cannot be dictionary keys or set members.
Related terms
- immutable — Something that cannot be changed after it is created; to change it you make a new one.
- hashable — Describes a Python object that has a hash value that never changes during its lifetime and can be compared for equality, so it can be a dict key or set member.
- aliasing — Having two or more names that refer to the same object, so a change made through one name shows up through the other.
- clone() — Making a separate, independent copy of an object, such as shape.clone() in graphics.py or a list copy with list(a).
- readonly — A modifier, in languages such as C# and TypeScript, that lets a field or property be assigned only when it is initialised, never afterwards.
- mapping modifier — A plus or minus sign before readonly or the optional question mark in a mapped type, which adds or removes that modifier from every property.
Taught in
- Python Dicts And Sets Under The Hood — Algorithms & Data Structures for Working Engineers
- Comparison Sorts: Insertion, Merge And Quicksort — Algorithms & Data Structures for Working Engineers
- Dictionaries — Hands-on Python: Complete Video Course & Book
- Lists, Range And The For Loop — Hands-on Python: Complete Video Course & Book
- String Slices — Hands-on Python: Complete Video Course & Book
- Appending To Lists, Sets, Constructors — Hands-on Python: Complete Video Course & Book
- Mutable Objects And Aliases — Hands-on Python: Complete Video Course & Book
- Chapter Two In One Sitting — Hands-on Python: Complete Video Course & Book
- Type Annotations, Type Inference And Contextual Typing — Production TypeScript
- Literal Types: String, Number, Boolean Literals And const — Production TypeScript
- void, undefined And null: Exact Optional Property Types — Production TypeScript
- Optional Properties, Readonly And Index Signatures — Production TypeScript
- Union Types, Intersections And Property Conflicts — Production TypeScript
- Tuples: Fixed Length, Labeled Elements And Variadic Tuples — Production TypeScript
- Const Type Parameters: Retaining Literal Types In Functions — Production TypeScript
- Core Utilities: Partial, Required, Readonly, Pick And Omit — Production TypeScript
- Union Utilities: Exclude, Extract, NonNullable And Awaited — Production TypeScript
- Mapped Types, Key Remapping With as And Template Literals — Production TypeScript
- Modern Decorators: Stage 3 Standards And Class Metadata — Production TypeScript
- read, readline, errno And bytearray — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comprehensions, Closures And Files Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Twelve Traps, Mostly Objects — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep