Python Data Types with Examples – Programming, Pseudocode Example, C# Programming Example
Python 3

Python Data Types with Examples

In this post, we will learn about the data type used in Python.

Every programming language has this same concept as the data type. Similarly, Python has a data type of every variable that is used in the code.

The datatype is very important in every programming language. Data can be stored with various types in a variable. Different data types can do different actions in the code.

n Python, every component is treated as an object. In that object, data types are treated as classes, and variables are treated as an instance of that class.

Python has several built-in data types. Those data types are classified below as a category format,

CategoryData type
Numericint, float, complex
Textstr
SequenceList, tuple, range
Mappingdist
Booleanbool
Setset, frozenset
Binarybyte, bytearray, memoryview

Getting Data type

To know the data type of a variable, we have to write the function type() and pass the parameter of that assigned variable. To check if an object belongs to a particular class or not, we have to write the function isinstance().

Example:

Various Data types with Examples

ExampleData type
a = “Hello Python”str
a = 100integer
a = 10.550float
a = 6jcomplex
a = [“TV”, “Mobile”, “Computer”]list
a = (“TV”, “Mobile”, “Computer”)tuple
a = range(10)range
a = {“Name” : “Devis”, “Age” : 50}dict
a = {“TV”, “Mobile”, “Computer”}set
a = frozenset({“TV”, “Mobile”, “Radio”})frozenset
a = Falsebool
a = b”PHP”bytes
a = bytearray(2)bytearray
a = memoryview(bytes(8))memoryview

Change Data type

It is possible to convert from one data type to another data type in Python. Some examples are given below

Example

Python List

It is one of the famous data types used in Python. It holds various items and is very much flexible. The list values can be used by brackets []. We will discuss more on this later. Here we are giving the basic idea of List.

Example

Python Tuple

It is one of the famous data types used in Python. It holds various items and is very much flexible. It is the same as the list but the only difference is that tuples are immutable. The tuple values can be used by brackets (). We will discuss more on this later. Here we are giving the basic idea of Tuple.

Example:

Python Dictionary

It is one of the most important data types in python. It is a collection of key-value pairs. It is used by brackets {}. We will discuss more on this later. Here we are giving the basic idea of a dictionary.

Example:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.