Hi, I'm mithushan. In this blog I am writing what I learn from online or other resources.

Wednesday, April 5, 2023

Python Data Types

    

Programming relies heavily on the concept of data types as it helps in defining the nature and range of operations that can be performed on a particular set of data.

Variables are used to store data in a program, and each variable can store data of a particular data type. Different data types in programming can perform different operations.

Python has a comprehensive set of built-in data types that come pre-defined with the language. These data types can be broadly categorized into the following categories:


  1. Numeric Types:
    1. int: integer numbers such as -3, 0, 7, and 100
    2. float: floating-point numbers such as 3.14, 2.0, and -0.5
    3. complex: complex numbers such as 2 + 3j and -1 - 4j
  2. Sequence Types:
    1. list: ordered, mutable, and allows duplicate elements such as [1, 2, 3] and ["apple", "banana", "orange"]
    2. tuple: ordered, immutable, and allows duplicate elements such as (1, 2, 3) and ("apple", "banana", "orange")
    3. range: represents an immutable sequence of numbers such as range(0, 10)
  3. Text Type:
    1. str: a string of characters such as "hello", "world", and "123"
  4. Mapping Type:
    1. dict: an unordered, mutable collection of key-value pairs such as {"name": "John", "age": 30}
  5. Set Types:
    1. set: an unordered, mutable collection of unique elements such as {1, 2, 3} and {"apple", "banana", "orange"}
    2. frozenset: an unordered, immutable collection of unique elements such as frozenset({1, 2, 3})
  6. Boolean Type:
    1. bool: represents a boolean value of either True or False
  7. Binary Types:
    1. bytes: represents a sequence of bytes such as b"hello"
    2. bytearray: represents a mutable sequence of bytes such as bytearray(b"hello")
    3. memoryview: represents a memory view of a byte array such as memoryview(b"hello")

No comments:

Post a Comment