Python Data Types

Python Data Types

Introduction

In Python programming, data types serve as the foundation for representing and manipulating different kinds of information. Understanding the various data types available in Python is essential for effective programming and data manipulation. In this blog post, we will explore the commonly used data types in Python with examples, enabling you to grasp their characteristics and usage in your programming endeavors.

Data Types

Numeric Data Types

Python provides numeric data types to represent numbers, including integers, floating-point numbers, and complex numbers.

  • Example 1: Integer (int).

    In this example, the variable age is assigned an integer value of 28.

  • Example 2: Floating-Point (float)

    Here, the variable pi is assigned a floating-point value representing the mathematical constant pi.

  • Example 3: Complex (complex)

    The variable c represents a complex number with a real part of 2 and an imaginary part of 3.

Text Data Type

In Python, text data is represented by the str (string) data type.

Example: String (str)

The variable message stores a string containing the greeting "Hello, World!".

Sequence Data Types

Python offers several sequence data types to work with ordered collections of items.

  • Example: List (list)

    The variable numbers represent a list containing a sequence of integers.

  • Example: Tuple (tuple)

    Here, the variable coordinates store a tuple with two elements representing coordinates.

    Mapping Data Type:

  • Python provides the dict (dictionary) data type to work with key-value pairs.

Example 8: Dictionary (dict)

The variable student represents a dictionary with keys (e.g., "name", "age", "grade") and their corresponding values.

Set Data Type

Python's set data type allows working with unordered collections of unique elements.

Example: Set (set)

The variable fruits stores a set of unique fruit names.