tuple
An ordered, fixed-length group of values in which each position can have its own meaning and type.
In more detail
Many languages have tuples: Python writes them in round brackets, such as (250, 2), while TypeScript and Terraform have tuple types such as [string, number] and tuple([string, number]). Unlike a list, a tuple's length is part of what it is. Python tuples cannot be changed once made, so they can be dictionary keys, and they are compared element by element from the left.
Examples
(x, y) as a dict key; (priority, task) as a heap entry; (neighbour, weight) for a weighted edge.The course's serializer keeps its public field names in a tuple, so a new column stays private until someone adds it there.kafka-python header: ('content-type', b'application/json')('content-type', b'application/json')The course's tuple trap: Line((1, 2), (3, 4)) fails because graphics.py wants Point objects, not tuples.point = (3, 4)
x, y = pointReact hooks return tuples such as [value, setValue] when callers usually rename the parts.const [isPending, startTransition] = useTransition();In Terraform a tuple is a structural type, such as tuple([string, number]). A literal list like ["a", 1] is a tuple until it is converted to a list type.In this course: The course represents each basket line as a tuple of price in pence and count. pytest's parametrize takes a list of tuples, one tuple per test case, in the same order as the parameter names.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.
- lexicographic order — Ordering sequences the way a dictionary orders words: compare the first elements, and only if they are equal move on to the next.
- priority queue — A collection where each item has a priority and the item removed next is always the one with the highest priority, not the oldest.
- serialization — Turning an in-memory object into bytes, such as JSON text, that can be sent or stored, and parsing it back again.
- Python — A popular general-purpose programming language known for readable code and a large standard library.
- as const — The TypeScript suffix as const, which tells the compiler to treat an object's values as fixed literal values rather than general types.
- query key — The array that names a piece of cached server data in TanStack Query, such as ["users", "detail", "10"].
- record header — A key and bytes-value pair attached to a record outside its value, used for metadata such as content type or a trace ID.
- dictionary — A Python collection that stores values under keys, written in curly brackets, such as {"tea": 250}.
- destructuring — JavaScript syntax that unpacks values from an object or array into separate named variables in one step.
- useActionState — The React hook that wraps an Action and returns its latest result, a function to trigger it, and an isPending flag.
- list — An ordered, changeable collection of values written in square brackets, such as [3, 1, 4].
- tuple unpacking — Assigning the items of a tuple or other sequence to several names at once, as in x, y = point.
- custom hook — Your own function whose name starts with use and that calls other hooks, packaging stateful logic so several components can reuse it.
- type constraint — The type argument of a variable, such as string, number, bool, list(string), map(string) or object({...}), which rejects values of the wrong shape.
- parametrized test — One test function run many times with different data, each run reported as a separate test case.
- labeled tuple element — A name written before a tuple position, such as [latitude: number, longitude: number], that documents what each slot means.
- variadic tuple — A tuple type containing a spread such as [query: string, ...params: (string | number)[]], so its length can vary.
- 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.
- Parameters<T> — The utility type that gives a function type's parameter list as a tuple, such as [orderId: string, priority: boolean].
Taught in
- Python Dicts And Sets Under The Hood — Algorithms & Data Structures for Working Engineers
- Sorting In Real Systems: Stability, Keys And External Sort — Algorithms & Data Structures for Working Engineers
- Heaps And Priority Queues — Algorithms & Data Structures for Working Engineers
- Representing A Graph: Matrix Or Adjacency List — Algorithms & Data Structures for Working Engineers
- Dijkstra: Shortest Paths With A Priority Queue — Algorithms & Data Structures for Working Engineers
- Backtracking: Search With Pruning — Algorithms & Data Structures for Working Engineers
- Upgrading For CVEs: Read The Feed, Then Patch — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Software Composition Analysis with Trivy — Cloud Security & DevSecOps Engineering
- Vendor & Third-Party Risk Management Programs — Cybersecurity Fundamentals, GRC & Cryptography
- Type-Safe Client Generation: Orval & Automated SDKs — Production Full-Stack Engineering
- Headers, Envelopes And Event Metadata — Apache Kafka & Event Streaming
- Audit Day: Final Review — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Async Data Fetching: Parallel Requests & Preloading — Next.js 15 & Modern App Router Architecture
- Action State: useActionState & Optimistic Form UI — Next.js 15 & Modern App Router Architecture
- Installing Python On A Mac — Hands-on Python: Complete Video Course & Book
- Where Python Lives: PATH And Versions — Hands-on Python: Complete Video Course & Book
- A Graphics Introduction — Hands-on Python: Complete Video Course & Book
- Loops And Tuples — Hands-on Python: Complete Video Course & Book
- Chapter Three In One Sitting — Hands-on Python: Complete Video Course & Book
- Lists, Tuples, Sets, Dicts: Choosing One — Hands-on Python: Complete Video Course & Book
- Custom Hook Composition: Encapsulating Reactive Logic — React 19 & Modern Component Architecture
- useActionState: Async Action Handlers And Pending States — React 19 & Modern Component Architecture
- Mass Assignment — Application Security & Threat Modeling for Engineers
- Parameterising With Input Variables — Infrastructure as Code with Terraform
- The Cost And Value Of A Test — Automated Testing, TDD & Quality Engineering
- Parametrised Tests — Automated Testing, TDD & Quality Engineering
- Literal Types: String, Number, Boolean Literals And const — Production TypeScript
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Discriminated Unions: Tagged Variants And Pattern Matching — Production TypeScript
- Tuples: Fixed Length, Labeled Elements And Variadic Tuples — Production TypeScript
- Generic Interfaces, Classes And Type Aliases — Production TypeScript
- Const Type Parameters: Retaining Literal Types In Functions — Production TypeScript
- Function Utilities: ReturnType, Parameters And Constructor — Production TypeScript
- Conditional Types: Ternary Types And Type Inference With infer — Production TypeScript
- The satisfies Operator: Safe Validation Without Widening — Production TypeScript
- Thirty Questions, One Sneaky Print — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Lists: Slices, Methods And Aliases — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Tuples, And The Comma That Makes Them — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Dictionaries: Keys, Values And Items — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Strings: Escapes, Slices And Methods — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Collections Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Functions, Return Values And Recursion — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Try, Except, Else And Finally — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Twelve Traps, One Shape Each — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- The Class That Shared One List — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- math, random And platform — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Modules Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Handlers, args, raise And assert — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exception Classes Of Your Own — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exceptions Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Introspection: hasattr, __name__, __module__ And __bases__ — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Multiple Inheritance, The MRO And Diamonds — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Generators And Iterators — 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
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Complex Types: Lists, Sets, Maps, Objects And Tuples — HashiCorp Terraform Associate (004) Exam Prep
- When awk Runs Out: Python Data Types, Modules And Virtual Environments For Admins — CompTIA Linux+ (XK0-006) Exam Prep
References
- Python tuples
- Python tutorial: tuples and sequences
- TypeScript: Tuple types
- Type constraints: structural types
- TypeScript Handbook: Object Types
Certification courses
- CKS course and practice exam: Certified Kubernetes Security Specialist
- KCSA course and practice exam: Kubernetes and Cloud Native Security Associate
- PCEP course and practice exam: Certified Entry-Level Python Programmer
- PCAP course and practice exam: Certified Associate in Python Programming
- Terraform Associate course and practice exam: HashiCorp Terraform Associate (004)
- CompTIA Linux+ course and practice exam: XK0-006