Python Data Types

Python · Variables & Data Types

Theory

Every value in Python has a type that decides what you can do with it. The core built-in types are: numbers (int, float, complex), text (str), booleans (bool), sequences (list, tuple, range), sets (set, frozenset), mappings (dict) and the special value None of type NoneType. type(value) tells you which one you have, and isinstance(value, int) checks it in a way that also accepts subclasses.

The most important split is mutable versus immutable. Immutable types (int, float, str, bool, tuple, frozenset) can never change after creation; any 'change' creates a new object. Mutable types (list, dict, set) can be modified in place, so every name pointing at them sees the change. Only immutable, hashable values can be dictionary keys or set members, which is why a list cannot be a dict key but a tuple can.

Why we use it

The type decides which operations are legal: 5 + 5 is 10, '5' + '5' is '55', and '5' + 5 is a TypeError. Knowing types lets you predict results, read error messages and pick the right container for your data.

When to use it

Use type() or isinstance() when debugging unexpected results or validating input. Pick list for ordered changeable data, tuple for fixed records, set for unique items, and dict for lookups by key. Prefer isinstance() over type() == in real code.

How it works

  1. You have a value, e.g. 3.14
  2. Python stores it as an object that carries its type
  3. Call type(3.14) to inspect it
  4. Is the type mutable (list, dict, set)? Yes: Can change in place; all names see it. No: Changes make a new object.
  5. Choose operations that type supports
  6. Output: <class 'float'>

Syntax

type(variable)

Example

type(3.14)  # float

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic