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