October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Python Data Types: A Practical Guide to Built-In Types

A practical guide to Python’s built-in types, with clear comparisons of mutability, indexing, hashability, and what each type represents.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python’s built-in data types represent numbers, true-or-false values, sequences, text, binary data, sets, and key-value mappings. Choose among them by asking what the value represents, whether it needs to change, and whether you need positions, uniqueness, or key-based lookup. This guide covers the core built-ins; Python has other built-in types beyond this introductory inventory.

What are the data types in Python?

A type defines what kind of value an object represents and which operations make sense for it. Python’s core built-in types include int, float, complex, bool, list, tuple, range, str, bytes, bytearray, memoryview, set, frozenset, and dict. The Python Software Foundation’s Python 3.14.8 built-in types documentation describes these families and their behavior.

Four properties help distinguish them:

  • Mutability: whether an object can be changed after it is created.
  • Ordering and indexing: whether values form a sequence with positions that can be accessed by index.
  • Hashability: whether a value can serve as a dictionary key or a set member. Immutable built-ins are not automatically hashable; their contents matter too.
  • Purpose: the kind of information the type is designed to represent.

Numeric types: int, float, and complex

The Python documentation identifies three distinct numeric types: integers, floating-point numbers, and complex numbers. Python integers have unlimited precision in the language’s documented semantics. A float is a floating-point value, normally represented using the C double format. A complex value has real and imaginary floating-point components.

  • int represents whole numbers, such as 42 or -7.
  • float represents floating-point numbers, such as 3.14.
  • complex represents values with real and imaginary parts, such as 2 + 3j.

decimal.Decimal and fractions.Fraction are useful numeric types in Python’s standard library, but they are not built-in numeric types.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Boolean values: bool

A Boolean represents a truth value and has exactly two values: True and False. The type bool is a subclass of int, so booleans can behave numerically like zero and one. The documentation discourages relying on that behavior without explicit conversion; use Boolean logic for conditions and convert deliberately when you need a number.

Sequences: list, tuple, and range

Sequences preserve positions and support indexing. Use a list when the collection should change, a tuple when its structure should stay fixed, and a range when you need a patterned sequence of integers.

List

A list is a mutable sequence. You can replace, add, or remove items, and access items by position. Lists are useful for collections that will be updated, such as a queue of tasks or a set of results gathered during a calculation.

Tuple

A tuple is an immutable sequence. Its elements cannot be replaced or removed after creation, making it suitable for a fixed group of values. The comma creates a tuple; parentheses are often used for clarity but are not what makes it one. For example, (x) is just x, while (x,) is a one-item tuple.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A tuple can be used as a dictionary key or set member only if every value it contains is hashable. Immutability alone does not guarantee hashability.

Range

A range is an immutable sequence representing a pattern of integers, commonly used for iteration. It stores the pattern rather than a separate copy of every represented integer, so it uses a small fixed amount of memory relative to the sequence length.

Text and binary data: str and the bytes family

Use str for text and bytes-family types for binary sequences. The Python documentation states that textual data is handled with str objects, or strings.

str for text

A str represents text, such as a name, sentence, or message. It is an immutable sequence of text characters, so it supports sequence operations such as indexing and slicing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

bytes and bytearray for binary sequences

bytes represents an immutable binary sequence; bytearray represents a mutable one. These types are appropriate when working with encoded text, file contents, or other data that must be handled as bytes rather than as text characters.

Turning bytes into text requires decoding with a specified encoding. For example, use data.decode('utf-8') or str(data, 'utf-8') when UTF-8 is the correct encoding. str(data) by itself does not decode the bytes.

memoryview for buffer access

A memoryview provides access to data in a buffer without copying that data. It is useful when code needs to inspect or work with buffer-backed data while avoiding an additional copy.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Sets and mappings: uniqueness versus key-value lookup

Use a set to track distinct hashable values, and a dictionary to associate hashable keys with values. Neither is a sequence for positional access.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

set and frozenset

A set contains distinct hashable objects. It is mutable and useful for checking membership or removing duplicates. Sets do not preserve sequence-style positions or support indexing. A frozenset is an immutable set; it is hashable and can therefore be used as a dictionary key or as a member of another set.

Use set() to create an empty set. Empty braces, {}, create an empty dictionary instead.

dict

A dict is a mutable mapping from hashable keys to values. Use it when a value should be retrieved by a meaningful key, such as looking up a user’s settings by option name. Dictionary values can be arbitrary objects; keys must be hashable.

Keys that compare equal can refer to the same dictionary entry. For example, 1, 1.0, and True compare equal and can address the same key.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which Python data type should you use?

If you need… Use Why
A collection with positions that you will change list Mutable sequence with indexing.
A fixed group of values in a particular order tuple Immutable sequence; it can be hashable if all its contents are hashable.
A patterned sequence of integers range Immutable integer sequence that stores a pattern rather than every value.
Lookup by a key dict Maps hashable keys to values.
Distinct values or fast membership checks set Stores unique hashable members without sequence indexing.
An immutable set that can itself be a key or set member frozenset Immutable and hashable.
Human-readable text str Python’s text type.
Mutable or immutable binary data bytearray or bytes Choose mutable bytearray or immutable bytes.
Access to buffer data without copying memoryview Exposes buffer data without making a copy.

For examples of common sequence and mapping operations, see the Python Software Foundation’s Python 3.14.8 data structures tutorial.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.