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

  • Class06,07 Operators, Expressions

    In Python, operators are special symbols that perform operations on variables and values. They are categorized based on their functionality: โš™๏ธ 1. Arithmetic Operators โž•โž–โœ–๏ธโž— Used for mathematical operations: Python 2. Assignment Operators โžก๏ธ Assign values to variables (often combined with arithmetic): Python 3. Comparison Operators โš–๏ธ Compare values โ†’ return True or False: Python…

  • Thonny: A User-Friendly Python IDE for Beginners in 2025

    Thonny is a free and open-source Integrated Development Environment (IDE) specifically designed for beginners learning Python. It provides a simple and user-friendly interface, making it an excellent choice for those new to programming. Key Features: Why Thonny is good for beginners: How to install Thonny: If you’re new to Python and looking for a user-friendly…

  • Inheritance in OOP Python: Rectangle & Cuboid Example

    Rectangle Inheritance in OOP Python: Rectangle & Cuboid Example Inheritance in object-oriented programming (OOP) allows a new class (the child class) to inherit properties and methods from an existing class (the parent class). This is a powerful concept for code reusability โ™ป๏ธ and establishing a logical “is-a” relationship between classes. For instance, a Cuboid is…

  • replace(), join(), split(), rsplit(), and splitlines() methods in Python

    1. replace() Method Purpose: Replaces occurrences of a substring with another substring.Syntax: python string.replace(old, new[, count]) Examples: Example 1: Basic Replacement python text = “Hello World” new_text = text.replace(“World”, “Python”) print(new_text) # Output: “Hello Python” Example 2: Limiting Replacements (count) python text = “apple apple apple” new_text = text.replace(“apple”, “orange”, 2) print(new_text) # Output: “orange orange apple”…

  • Generators in Python

    Generators in Python What is a Generator? A generator is a special type of iterator that allows you to iterate over a sequence of values without storing them all in memory at once. Generators generate values on-the-fly (lazy evaluation) using the yield keyword. Key Characteristics Basic Syntax python def generator_function(): yield value1 yield value2 yield value3 Simple Examples Example…

  • re.I, re.S, re.X

    Python re Flags: re.I, re.S, re.X Explained Flags modify how regular expressions work. They’re used as optional parameters in re functions like re.search(), re.findall(), etc. 1. re.I or re.IGNORECASE Purpose: Makes the pattern matching case-insensitive Without re.I (Case-sensitive): python import re text = “Hello WORLD hello World” # Case-sensitive search matches = re.findall(r’hello’, text) print(“Case-sensitive:”, matches) # Output: [‘hello’] # Only finds lowercase…

Leave a Reply

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