Built-in Data Types<br />In programming, data type is an important concept.<br /><br />Variables can store data of different types, and different types can do different things.<br /><br />Python has the following data types built-in by default, in these categories:<br /><br />Text Type: str<br />Numeric Types: int, float, complex<br />Sequence Types: list, tuple, range<br />Mapping Type: dict<br />Set Types: set, frozenset<br />Boolean Type: bool<br />Binary Types: bytes, bytearray, memoryview<br />None Type: NoneType<br />Getting the Data Type<br />You can get the data type of any object by using the type() function:<br /><br />ExampleGet your own Python Server<br />Print the data type of the variable x:<br /><br />x = 5<br />print(type(x))<br />Setting the Data Type<br />In Python, the data type is set when you assign a value to a variable:<br /><br />Example Data Type Try it<br />x = "Hello World" str <br />x = 20 int <br />x = 20.5 float <br />x = 1j complex <br />x = ["apple", "banana", "cherry"] list <br />x = ("apple", "banana", "cherry") tuple <br />x = range(6) range <br />x = {"name" : "John", "age" : 36} dict <br />x = {"apple", "banana", "cherry"} set <br />x = frozenset({"apple", "banana", "cherry"}) frozenset <br />x = True bool <br />x = b"Hello" bytes <br />x = bytearray(5) bytearray <br />x = memoryview(bytes(5)) memoryview <br />x = None NoneType <br />ADVERTISEMENT<br /><br />Setting the Specific Data Type<br />If you want to specify the data type, you can use the following constructor functions:<br /><br />Example Data Type Try it<br />x = str("Hello World") str <br />x = int(20) int <br />x = float(20.5) float <br />x = complex(1j) complex <br />x = list(("apple", "banana", "cherry")) list <br />x = tuple(("apple", "banana", "cherry")) tuple <br />x = range(6) range <br />x = dict(name="John", age=36) dict <br />x = set(("apple", "banana", "cherry")) set <br />x = frozenset(("apple", "banana", "cherry")) frozenset <br />x = bool(5) bool <br />x = bytes(5) bytes <br />x = bytearray(5) bytearray <br />x = memoryview(bytes(5)) memoryview