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

  • Type Conversion Functions

    Type Conversion Functions in Python ๐Ÿ”„ Type conversion (or type casting) transforms data from one type to another. Python provides built-in functions for these conversions. Here’s a comprehensive guide with examples: 1. int(x) ๐Ÿ”ข Converts x to an integer. Python 2. float(x) afloat Converts x to a floating-point number. Python 3. str(x) ๐Ÿ’ฌ Converts x…

  • Functions as Parameters in Python

    Functions as Parameters in Python In Python, functions are first-class objects, which means they can be: Basic Concept When we pass a function as a parameter, we’re essentially allowing one function to use another function’s behavior. Simple Examples Example 1: Basic Function as Parameter python def greet(name): return f”Hello, {name}!” def farewell(name): return f”Goodbye, {name}!” def…

  • Password Strength Checker

    python Enhanced Password Strength Checker python import re def is_strong(password): “”” Check if a password is strong based on multiple criteria. Returns (is_valid, message) tuple. “”” # Define criteria and error messages criteria = [ { ‘check’: len(password) >= 8, ‘message’: “at least 8 characters” }, { ‘check’: bool(re.search(r'[A-Z]’, password)), ‘message’: “one uppercase letter (A-Z)”…

  • Vs code

    What is VS Code? ๐Ÿ’ป Visual Studio Code (VS Code) is a free, lightweight, and powerful code editor developed by Microsoft. It supports multiple programming languages (Python, JavaScript, Java, etc.) with: VS Code is cross-platform (Windows, macOS, Linux) and widely used for web development, data science, and general programming. ๐ŸŒ๐Ÿ“Šโœ๏ธ How to Install VS Code…

  • Python Nested Lists

    Python Nested Lists: Explanation & Examples A nested list is a list that contains other lists as its elements. They are commonly used to represent matrices, tables, or hierarchical data structures. 1. Basic Nested List Creation python # A simple 2D list (matrix) matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9]…

Leave a Reply

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