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

  • re.subn()

    Python re.subn() Method Explained The re.subn() method is similar to re.sub() but with one key difference: it returns a tuple containing both the modified string and the number of substitutions made. This is useful when you need to know how many replacements occurred. Syntax python re.subn(pattern, repl, string, count=0, flags=0) Returns: (modified_string, number_of_substitutions) Example 1: Basic Usage with Count Tracking python import re…

  • Variable Length Keyword Arguments in Python

    Variable Length Keyword Arguments in Python Variable length keyword arguments allow a function to accept any number of keyword arguments. This is done using the **kwargs syntax. Syntax python def function_name(**kwargs): # function body # kwargs becomes a dictionary containing all keyword arguments Simple Examples Example 1: Basic **kwargs python def print_info(**kwargs): print(“Information received:”, kwargs) print(“Type of…

  • Python Functions

    A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. Defining a Function In Python, a function is defined using the def keyword, followed by the function name, a set of parentheses (),…

  • Keyword-Only Arguments in Python and mixed

    Keyword-Only Arguments in Python Keyword-only arguments are function parameters that must be passed using their keyword names. They cannot be passed as positional arguments. Syntax Use the * symbol in the function definition to indicate that all parameters after it are keyword-only: python def function_name(param1, param2, *, keyword_only1, keyword_only2): # function body Simple Examples Example 1: Basic Keyword-Only Arguments…

  • recursive function

    A recursive function is a function that calls itself to solve a problem. It works by breaking down a larger problem into smaller, identical subproblems until it reaches a base case, which is a condition that stops the recursion and provides a solution to the simplest subproblem. The two main components of a recursive function…

Leave a Reply

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