October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober 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: Pick the Right Type for Each Value

A practical guide to Python’s common built-in types, mutability, and choosing the right collection for your data.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python data types tell you what a value is and which operations it supports. For everyday code, choose a list for an ordered sequence you may change, a tuple for a sequence whose slots should stay fixed, a set for unique values, and a dictionary for looking up values by key.

What is a data type in Python?

Python represents data as objects. Each object has an identity, a type, and a value; its type determines the operations it supports. For example, you can add numbers, join strings, append to a list, or retrieve a dictionary value by key. These are common built-in types, not a complete list of every type available in Python.

As an Amazon Associate I earn from qualifying purchases.

The examples below use the built-in types documented in Python 3.14.7’s built-in types reference.

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

Common Python types at a glance

Type Example What it represents
int 12 An integer; Python integers have unlimited precision.
float 3.5 A floating-point number.
complex 2 + 3j A number with real and imaginary components.
bool True A Boolean value: True or False. bool is a subtype of int.
str "Ada" Immutable text. Python has no separate character type; a one-code-point string is still a str.
list [8, 9, 10] An ordered, mutable sequence that can contain repeated values and values of different types.
tuple (2, 5) An ordered, immutable sequence.
range range(5) A sequence representing an arithmetic progression, rather than a stored list of all its values.
bytes b"ABC" Immutable binary data.
bytearray bytearray(b"ABC") Mutable binary data.
set {"python", "beginner"} An unordered collection of unique elements.
frozenset frozenset({"python", "beginner"}) An immutable set.
dict {"name": "Ada"} A mutable mapping of unique keys to values.

How do you check a value’s type?

Use type(value) to see the value’s type:

name = "Ada"
print(type(name))  # <class 'str'>

When checking whether an object belongs to a type or one of its subclasses, Python’s isinstance(value, SomeType) is generally the more useful check:

if isinstance(name, str):
    print("name is text")

Which Python collection should you use?

Collection Organization and duplicates Can contents change? Typical access
list Ordered sequence; repeats are allowed. Yes. Index, slice, or iteration.
tuple Ordered sequence; repeats are allowed. No, its slots cannot be reassigned. Index, slice, or iteration.
set Unique elements; no sequence order or indexing. Yes. Membership tests and set operations.
dict Unique keys associated with values; insertion order is preserved. Yes. Lookup by key.

This practical distinction follows the Python data structures tutorial: choose based on how you need to organize and access data.

Use a list for a sequence you will change

Lists keep items in order and allow updates, additions, and removals. They can hold mixed types, though lists of one kind of value are common.

scores = [8, 9, 10]
scores.append(11)
print(scores)  # [8, 9, 10, 11]

Use a tuple when the sequence’s slots should stay fixed

A tuple is ordered like a list but immutable: you cannot reassign one of its slots after creation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
point = (2, 5)
# point[0] = 3  # Raises TypeError

Immutability applies to the tuple’s references, not automatically to every object inside it. If a tuple contains a list, that list can still change:

items = ([1, 2], "label")
items[0].append(3)
print(items)  # ([1, 2, 3], 'label')

Use a set for uniqueness and membership

A set removes duplicate elements and supports membership tests and operations such as union, intersection, difference, and symmetric difference. Sets are unordered and do not support indexing.

tags = {"python", "beginner", "python"}
print(tags)  # Contains one "python" element
print("beginner" in tags)  # True

languages = {"python", "ruby"}
print(tags & languages)  # Intersection

Use set() to create an empty set. Curly braces by themselves create an empty dictionary instead:

empty_set = set()
empty_dict = {}

Use a dictionary for key-to-value lookup

A dictionary maps unique keys to values. Retrieve a value using its key, not a numeric sequence position. Current Python dictionaries preserve insertion order, but their purpose is key-based mapping.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
profile = {"name": "Ada", "active": True}
print(profile["name"])  # Ada

Dictionary keys must be hashable, so they can be used consistently as keys. Lists and dictionaries are mutable and cannot serve as dictionary keys. Numeric keys that compare equal, such as 1 and 1.0, refer to the same dictionary entry.

What does mutable or immutable mean?

A mutable object can be changed after it is created; an immutable object cannot. This matters when two variables refer to the same object: changing a mutable object through one reference is visible through the other.

scores = [8, 9]
alias = scores
scores.append(10)
print(alias)  # [8, 9, 10]

Lists and dictionaries are mutable. Strings and numbers are immutable, as are tuples themselves. Trying to assign a character in a string raises TypeError:

name = "Ada"
# name[0] = "E"  # Raises TypeError

A tuple’s immutability prevents changing its slots, but—as shown above—a mutable object stored in a slot can still be modified. Python’s data model documentation explains the distinction between objects, types, values, and mutability.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Numbers, truth values, and absence

Numeric types

Python’s built-in numeric types are int, float, and complex. Integers have unlimited precision. Floats are floating-point values, and complex numbers have real and imaginary components.

bool is a subtype of int. True and False are Boolean values, although they also participate in the integer type relationship.

Truthiness

Objects can be tested in conditions. By default an object is true unless its class defines false behavior through __bool__() or a zero-length result from __len__(). Empty strings and collections are false.

if []:
    print("not printed")

if "hello":
    print("this runs")

None

None is a distinct built-in singleton commonly used to represent the absence of a value. It is not the same as False, 0, or an empty string.

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

Binary data and additional built-ins

For file, encoding, or network work, Python also provides binary-data types. bytes is immutable, bytearray is mutable, and memoryview provides a view over binary data. These are useful when working with bytes rather than ordinary text; the built-in types reference describes their behavior.

For more practice with these everyday values and collections, the official Python tutorial’s informal introduction includes practical examples.

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 *

Free tools Windows power users keep installed

One-click scans. No signup required.

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.