Python Data types

In the programming language, Data types are classification or kinds of data item values. Built-in types come with a programming language, if needed programmers can create their own data type to solve specific problems. Python has various Built-in Data types, this section will cover all Built-in data types and their use.


Objectives

  • Built-in Data types and their description

  • Example of Built-in Data types


Python Built-in Data types and their description

  • Text

    • str : Sequence of characters.

  • Number

    • int : Holds signed integers of non-limited length.

    • float : Holds floating precision numbers, and it’s accurate up to 15 decimal places.

    • complex : Holds complex numbers.

  • Collections

    • list : Set of data in single place, can accessible by index.

    • tuple : Tuple is an ordered sequence of items same as a list.

    • dict : Dictionary is an unordered collection of key-value pairs.

    • range : return sequence of number

    • set : Sequence of data similar to a list, but it is immutable.

    • frozenset : Make unchangeable

  • Boolean

    • bool : Represent only True or False.

  • Binary

    • bytes : returns a bytes object.

    • bytearray : returns a bytearray object.

    • memoryview : returns a memory view object


Python example of Built-in Data types

Data Type Example

str

str_variable = "Bismillah"

int

int_variable = 100

float

float_variable = 100.01

complex

complex_variable = 20j

list

list_variable = [10, "Mzx", 20.2]

tuple

tuple_variable = ("A", "B", "C")

range

range_variable = range(100)

dict

dict_variable = {"name": "Touhid Mia", "email": "hmtmcse.com@gmail.com"}

set

set_variable = {"A", "B", "C"}

frozenset

frozenset_variable = frozenset({"A", "B", "C"})

bool

bool_variable = False

bytes

bytes_variable = b"Bismillah"

bytearray

bytearray_variable = bytearray(100)

memoryview

memoryview_variable = memoryview(bytes(100))


Python Built-in Data types video tutorial