CS Engineering Gyan

Data Types in Python

Data types are one of the most important concepts in Python programming. Every value stored in a variable belongs to a particular data type. The data type determines what kind of value can be stored, how much memory is required, and what operations can be performed on that value.

Python automatically identifies the data type of a variable based on the value assigned to it. Because Python is a dynamically typed language, programmers do not need to explicitly declare data types before creating variables.

Understanding data types is essential for writing efficient programs, performing calculations, managing collections of data, and building real-world applications.

What are Data Types in Python?

A data type is a classification that specifies the kind of value stored inside a variable. Different types of data require different storage methods and support different operations.

For example, numbers can be added and multiplied, while text values can be concatenated and searched. Python provides several built-in data types to handle different categories of information.

x = 100
name = "Python"
price = 99.99

In the above example:

Classification of Python Data Types

Data Types in Python

Python data types can be broadly divided into several categories such as Numeric Types, Sequence Types, Set Types, Mapping Types, Boolean Type, and None Type.

Main Categories of Data Types

  • Numeric Types
  • Sequence Types
  • Set Types
  • Mapping Type
  • Boolean Type
  • None Type

Each category serves a different purpose and is used in different programming situations.

1. Numeric Data Types

Numeric data types are used to store numerical values. Python supports three major numeric types.

  • Integer (int)
  • Float (float)
  • Complex (complex)

Integer (int)

Integers represent whole numbers without decimal points.

age = 20
marks = 95

Float (float)

Floats represent decimal values.

price = 99.99
percentage = 85.5

Complex (complex)

Complex numbers contain a real part and an imaginary part.

x = 4 + 5j

2. Sequence Data Types

Sequence data types store multiple values in an ordered manner. Python provides three major sequence types.

Sequence Data Types
  • String
  • List
  • Tuple

String Data Type

A string is a collection of characters enclosed within single quotes, double quotes, or triple quotes.

name = "CSE Gyan"

Strings are immutable, which means their content cannot be modified after creation.

Features of String

  • Stores textual data
  • Supports indexing
  • Supports slicing
  • Immutable in nature

Example

message = "Python"

print(message[0])

Output

P

List Data Type

A list is an ordered collection of items enclosed within square brackets.

numbers = [10, 20, 30, 40]

Lists are mutable, which means elements can be added, removed, or modified.

Features of List

  • Ordered collection
  • Allows duplicate values
  • Mutable
  • Supports indexing and slicing

Example

fruits = ["Apple", "Mango", "Orange"]

fruits.append("Banana")

print(fruits)

Tuple Data Type

A tuple is an ordered collection of elements enclosed within parentheses.

data = (1, 2, 3, 4)

Unlike lists, tuples are immutable.

Features of Tuple

  • Ordered collection
  • Allows duplicates
  • Immutable
  • Faster than lists

Example

colors = ("Red", "Green", "Blue")

print(colors[1])

Output

Green

3. Set Data Type

A set is an unordered collection of unique elements enclosed within curly braces.

numbers = {10, 20, 30, 40}

Sets automatically remove duplicate values.

Features of Set

  • Unordered
  • No duplicate values
  • Mutable
  • Supports mathematical operations

Example

data = {10, 20, 20, 30}

print(data)

Output

{10, 20, 30}

4. Dictionary Data Type

A dictionary stores data in key-value pairs.

student = {
    "name":"Rahul",
    "age":20,
    "marks":85
}

Each key must be unique and is used to access its corresponding value.

Features of Dictionary

  • Stores key-value pairs
  • Fast data retrieval
  • Mutable
  • Keys must be unique

Example

student = {
    "name":"Amit",
    "age":21
}

print(student["name"])

Output

Amit

5. Boolean Data Type

Boolean data type represents logical values.

There are only two Boolean values:

  • True
  • False
isLoggedIn = True
isAdmin = False

Boolean values are widely used in conditions and decision-making statements.

6. None Data Type

The None type represents the absence of a value.

data = None

It is commonly used when a variable is declared but no actual value has been assigned yet.

Checking Data Type Using type()

Python provides the built-in type() function to identify the type of a variable.

x = 100

print(type(x))

Output

<class 'int'>

Difference Between List and Tuple

Feature List Tuple
Syntax [] ()
Mutable Yes No
Performance Slower Faster
Memory Usage Higher Lower

Advantages of Python Data Types

  • Easy data management
  • Automatic type detection
  • Efficient memory utilization
  • Supports complex applications
  • Improves code readability
  • Provides built-in operations
  • Suitable for beginners
  • Supports multiple programming paradigms

Summary of Python Data Types

  • Numeric → int, float, complex
  • Sequence → string, list, tuple
  • Set → unique unordered values
  • Dictionary → key-value pairs
  • Boolean → True or False
  • None → absence of value

Understanding data types is fundamental for mastering Python programming because every program relies on storing, processing, and manipulating different kinds of data.

Conclusion

Data types form the foundation of Python programming. They define how information is stored, processed, and manipulated inside a program. Python offers a rich collection of built-in data types including Numeric, String, List, Tuple, Set, Dictionary, Boolean, and None types.

Choosing the correct data type improves program performance, readability, and maintainability. A strong understanding of Python data types helps programmers write efficient code and build reliable applications.


Home Visit Our YouTube Channel