Various types of data types in python


šŸ”¢ Numeric Types

Used for storing numbers:

  • int: Integer values, e.g., 42, -7
  • float: Floating-point numbers (decimals), e.g., 3.14, -0.001
  • complex: Complex numbers, e.g., 2 + 3j

šŸ”” Text Type

Used for textual data:

  • str: A sequence of characters, e.g., "hello world"

šŸ“¦ Sequence Types

Ordered collections:

  • list: Mutable, ordered, e.g., [1, 2, 3]
  • tuple: Immutable, ordered, e.g., (1, 2, 3)
  • range: Represents a range of values, e.g., range(0, 10)

šŸ”‘ Mapping Type

Used for key-value pairs:

  • dict: e.g., {"name": "Ramesh", "age": 30}

🧮 Set Types

Collections of unique elements:

  • set: Unordered, mutable, no duplicates, e.g., {1, 2, 3}
  • frozenset: Immutable version of a set

āœ… Boolean Type

  • bool: Logical values True or False

šŸŖ™ Binary Types

Used to handle binary data:

  • bytes: Immutable sequence of bytes
  • bytearray: Mutable version of bytes
  • memoryview: Access internal data of objects without copying

Want to explore examples of each, or dive deeper into when to use which type? I’d be happy to break it down even further.

Examples
šŸ”¢ Numeric Types

  • int:pythonage = 30
  • float:pythonpi = 3.14159
  • complex:pythonz = 2 + 5j

šŸ”” Text Type

  • str:pythongreeting = "Hello, Ramesh!"

šŸ“¦ Sequence Types

  • list:pythonfruits = ["apple", "banana", "cherry"]
  • tuple:pythoncoordinates = (10.0, 20.0)
  • range:pythonnumbers = range(1, 6) # 1 to 5

šŸ”‘ Mapping Type

  • dict:pythonperson = {"name": "Ramesh", "city": "Hyderabad", "age": 30}

🧮 Set Types

  • set:pythonunique_numbers = {1, 2, 3, 2} # duplicates ignored
  • frozenset:pythonfrozen = frozenset(["python", "java", "python"])

āœ… Boolean Type

  • bool:pythonis_active = True

šŸŖ™ Binary Types

memoryview:pythonview = memoryview(b"example")

bytes:pythondata = b"hello"

bytearray:pythonmutable_data = bytearray([65, 66, 67])

Similar Posts

  • group() and groups()

    Python re group() and groups() Methods Explained The group() and groups() methods are used with match objects to extract captured groups from regex patterns. They work on the result of re.search(), re.match(), or re.finditer(). group() Method groups() Method Example 1: Basic Group Extraction python import retext = “John Doe, age 30, email: john.doe@email.com”# Pattern with multiple capture groupspattern = r'(\w+)\s+(\w+),\s+age\s+(\d+),\s+email:\s+([\w.]+@[\w.]+)’///The Pattern: r'(\w+)\s+(\w+),\s+age\s+(\d+),\s+email:\s+([\w.]+@[\w.]+)’Breakdown by Capture…

  • Function Returns Multiple Values in Python

    Function Returns Multiple Values in Python In Python, functions can return multiple values by separating them with commas. These values are returned as a tuple, but they can be unpacked into individual variables. Basic Syntax python def function_name(): return value1, value2, value3 # Calling and unpacking var1, var2, var3 = function_name() Simple Examples Example 1:…

  • What is list

    In Python, a list is a built-in data structure that represents an ordered, mutable (changeable), and heterogeneous (can contain different data types) collection of elements. Lists are one of the most commonly used data structures in Python due to their flexibility and dynamic nature. Definition of a List in Python: Example: python my_list = [1, “hello”, 3.14,…

  • Formatted printing

    C-Style String Formatting in Python Python supports C-style string formatting using the % operator, which provides similar functionality to C’s printf() function. This method is sometimes called “old-style” string formatting but remains useful in many scenarios. Basic Syntax python “format string” % (values) Control Characters (Format Specifiers) Format Specifier Description Example Output %s String “%s” % “hello” hello %d…

  • Random Module?

    What is the Random Module? The random module in Python is used to generate pseudo-random numbers. It’s perfect for: Random Module Methods with Examples 1. random() – Random float between 0.0 and 1.0 Generates a random floating-point number between 0.0 (inclusive) and 1.0 (exclusive). python import random # Example 1: Basic random float print(random.random()) # Output: 0.5488135079477204 # Example…

  • Create lists

    In Python, there are multiple ways to create lists, depending on the use case. Below are the most common methods: 1. Direct Initialization (Using Square Brackets []) The simplest way to create a list is by enclosing elements in square brackets []. Example: python empty_list = [] numbers = [1, 2, 3, 4] mixed_list = [1, “hello”, 3.14,…

Leave a Reply

Your email address will not be published. Required fields are marked *