codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐍

Python Programming

7 / 68 topics
7Python Data Types Overview8Python Numbers & Math9Python Type Conversion (Casting)10Python Booleans & None11Python Strings & Methods12Python String Formatting13Python Operators & Precedence
Tutorials/Python Programming/Python Data Types Overview
🐍Python Programming

Python Data Types Overview

Updated 2026-05-15
25 min read

Python Data Types Overview

In this tutorial, we will explore the fundamental data types available in Python. Understanding these data types is crucial for any programmer as they form the building blocks of more complex data structures and algorithms. Whether you're a beginner or an experienced developer, having a solid grasp of Python's data types will significantly enhance your coding skills.

Introduction

Python provides several built-in data types that allow you to store and manipulate different kinds of data. These data types can be categorized into two main groups: primitive (or basic) data types and composite (or structured) data types. In this section, we'll cover the following primitive data types:

  • int: Integer numbers
  • float: Floating-point numbers
  • complex: Complex numbers
  • str: Strings
  • bool: Boolean values

And the following composite data types:

  • list: Ordered collections of items
  • tuple: Immutable ordered collections of items
  • set: Unordered collections of unique items
  • dict: Key-value pairs

We'll also discuss how to check the type of a variable using the type() function and how to perform type checking with the isinstance() function.

Core Content

1. Primitive Data Types

1.1 Integer (int)

An integer is a whole number without any decimal points. Python's int type can handle arbitrarily large integers, limited by available memory.

int_example.py
1# Example of int data type
2a = 42
3b = -100
4
5print("Type of a:", type(a))
6print("Type of b:", type(b))
Output
Type of a: <class 'int'>
Type of b: <class 'int'>

1.2 Floating-Point (float)

A floating-point number is a decimal number that can have fractional parts. Python's float type follows the IEEE 754 standard for double-precision floating-point numbers.

float_example.py
1# Example of float data type
2x = 3.14
3y = -0.001
4
5print("Type of x:", type(x))
6print("Type of y:", type(y))
Output
Type of x: <class 'float'>
Type of y: <class 'float'>

1.3 Complex (complex)

A complex number has a real part and an imaginary part, represented as a + bj. Python's complex type is used to handle such numbers.

complex_example.py
1# Example of complex data type
2z = 2 + 3j
3w = -1.5 - 0.5j
4
5print("Type of z:", type(z))
6print("Type of w:", type(w))
Output
Type of z: <class 'complex'>
Type of w: <class 'complex'>

1.4 String (str)

A string is a sequence of characters enclosed in quotes (single, double, or triple). Strings are immutable, meaning they cannot be changed after creation.

string_example.py
1# Example of str data type
2name = "Alice"
3greeting = 'Hello, World!'
4
5print("Type of name:", type(name))
6print("Type of greeting:", type(greeting))
Output
Type of name: <class 'str'>
Type of greeting: <class 'str'>

1.5 Boolean (bool)

A boolean value can be either True or False. Booleans are often used in conditional statements to control the flow of a program.

bool_example.py
1# Example of bool data type
2is_raining = True
3has_umbrella = False
4
5print("Type of is_raining:", type(is_raining))
6print("Type of has_umbrella:", type(has_umbrella))
Output
Type of is_raining: <class 'bool'>
Type of has_umbrella: <class 'bool'>

2. Composite Data Types

2.1 List (list)

A list is an ordered collection of items that can be of different types. Lists are mutable, meaning you can modify them after creation.

list_example.py
1# Example of list data type
2fruits = ["apple", "banana", "cherry"]
3numbers = [1, 2, 3, 4, 5]
4
5print("Type of fruits:", type(fruits))
6print("Type of numbers:", type(numbers))
Output
Type of fruits: <class 'list'>
Type of numbers: <class 'list'>

2.2 Tuple (tuple)

A tuple is similar to a list, but it is immutable. Once created, the contents of a tuple cannot be changed.

tuple_example.py
1# Example of tuple data type
2coordinates = (10, 20)
3colors = ("red", "green", "blue")
4
5print("Type of coordinates:", type(coordinates))
6print("Type of colors:", type(colors))
Output
Type of coordinates: <class 'tuple'>
Type of colors: <class 'tuple'>

2.3 Set (set)

A set is an unordered collection of unique items. Sets are mutable and support operations like union, intersection, and difference.

set_example.py
1# Example of set data type
2unique_numbers = {1, 2, 3, 4, 5}
3vowels = {'a', 'e', 'i', 'o', 'u'}
4
5print("Type of unique_numbers:", type(unique_numbers))
6print("Type of vowels:", type(vowels))
Output
Type of unique_numbers: <class 'set'>
Type of vowels: <class 'set'>

2.4 Dictionary (dict)

A dictionary is a collection of key-value pairs where each key is unique. Dictionaries are mutable and allow for fast lookups.

dict_example.py
1# Example of dict data type
2person = {"name": "Alice", "age": 30, "city": "New York"}
3prices = {"apple": 1.2, "banana": 0.5, "cherry": 2.0}
4
5print("Type of person:", type(person))
6print("Type of prices:", type(prices))
Output
Type of person: <class 'dict'>
Type of prices: <class 'dict'>

3. Special Data Type: NoneType

NoneType is a special data type that represents the absence of a value or a null value.

none_example.py
1# Example of NoneType
2nothing = None
3
4print("Type of nothing:", type(nothing))
Output
Type of nothing: <class 'NoneType'>

4. Type Checking with type() and isinstance()

4.1 Using type()

The type() function returns the type of an object.

type_checking.py
1# Example of using type()
2a = 10
3b = "Hello"
4c = [1, 2, 3]
5
6print("Type of a:", type(a))
7print("Type of b:", type(b))
8print("Type of c:", type(c))
Output
Type of a: <class 'int'>
Type of b: <class 'str'>
Type of c: <class 'list'>

4.2 Using isinstance()

The isinstance() function checks if an object is an instance of a specific type or a tuple of types.

isinstance_checking.py
1# Example of using isinstance()
2a = 10
3b = "Hello"
4c = [1, 2, 3]
5
6print("Is a an int?", isinstance(a, int))
7print("Is b a str?", isinstance(b, str))
8print("Is c a list or tuple?", isinstance(c, (list, tuple)))
Output
Is a an int? True
Is b a str? True
Is c a list or tuple? True

Practical Example

Let's create a simple program that checks the types of various variables and performs some basic operations.

practical_example.py
1# Practical example: Type checking and operations
2def describe_variable(var):
3 var_type = type(var).__name__
4 print(f"The variable is of type {var_type}.")
5
6def main():
7 num1 = 42
8 num2 = 3.14
9 name = "Alice"
10 is_student = True
11 grades = [90, 85, 78]
12 person = {"name": "Bob", "age": 25}
13
14 describe_variable(num1)
15 describe_variable(num2)
16 describe_variable(name)
17 describe_variable(is_student)
18 describe_variable(grades)
19 describe_variable(person)
20
21if __name__ == "__main__":
22 main()
Output
The variable is of type int.
The variable is of type float.
The variable is of type str.
The variable is of type bool.
The variable is of type list.
The variable is of type dict.

Summary

Data TypeDescription
intInteger numbers
floatFloating-point numbers
complexComplex numbers
strStrings
boolBoolean values
listOrdered collections of items
tupleImmutable ordered collections of items
setUnordered collections of unique items
dictKey-value pairs
NoneTypeAbsence of a value

What's Next?

In the next tutorial, we will dive deeper into numbers and mathematical operations in Python. We'll explore arithmetic operators, number formatting, and more advanced numerical functions. Stay tuned!

Tip

Understanding data types is essential for effective programming. Always ensure that your variables are of the correct type to avoid unexpected errors.

Warning

Be cautious when using mutable data types like lists and dictionaries, as they can be changed in place without creating a new object.

Note

The type() function returns the exact type of an object, while isinstance() checks for compatibility with a specified type or tuple of types.


PreviousPython Basic Input and OutputNext Python Numbers & Math

Recommended Gear

Python Basic Input and OutputPython Numbers & Math