Data types are one of the most important components of python. You can do a lot of interesting things with these data types. It is a fact that in python, all data types are objects.
| Join the channel Telegram belong to AnonyViet 👉 Link 👈 |

Data type is like a characteristic of the type of data you want to store in memory and python has some of the following built-in data types:
- String text type: str
- Number type: int, float, complex
- Sequence types: list, tuple, range
- Mapping type: dict
- Set data type: set, frozenset
- Boolean type: bool
- Binary type: byte, bytearray, memoryview
Now, let’s classify all these data types using functions type() to display the variable’s data type.
Text format
String data type str
str is short for string used to store text in python. Strings can be written in double or single quotes, so you can write like this:
For example:

Result:
Hello, world!
Number type
Integer data type int
int is short for integer (integer) used to store integers (positive and negative integers).
For example:

Result:
4
Float real number data type
float stands for real number (decimal number).
For example:

Result:
3.14
Complex numbers have real parts and imaginary parts, each part is a real number. Complex numbers can be written in two forms: real + (imag)jcomplex(real, imag).
For example:

Result:
(5+10j)
Sequence type data type
list. list
List is a data type where you can store a collection of data. List can also contain different data types. List can also sort, change elements and allow elements to appear duplicated
For example:

Result:
['Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye']
tuple
Tuple is a data type where you can store a collection of data. Tuples can also contain different data types. Tuples are sortable, elements cannot be changed, and duplicate elements are allowed.
For example:

Result:
('Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye')
range. range
The range type represents an immutable (unchangeable) series of numbers. Usually used to repeat a specific number of times in a for loop.
For example:

Result:
range(0, 10)
Mapping data type
dict
dict is short for dictionary in python. Dict is used to store data values in key:values. A Dict is an unordered, mutable collection that does not allow duplicates.
For example:
Result:
{'Learning': 'Programming', 'Language': 'Python', 'Day': 4}
Data type Set
set
set is a data type where you can contain a collection of data. Sets can also contain different data types. Sets are unordered and unindexed, and duplicate elements are not allowed.
For example:

Result:
{'Black Widow', 'Iron Man', 'Thor', 'Hawkeye', 'Hulk', 'Captain America'}
frozenset
The frozenset data type can be created by the function frozenset(). Jaw frozenset() accepts an iterable object and returns an immutable frozenset object (like a set object, just immutable).
For example:

Result:
frozenset({'cherry', 'banana', 'apple'})
Boolean type
bool
bool stands for boolean in python. Booleans represent one of two values: True or False.
For example:

Result:
TrueFalse
Binary type
bytes
The byte data type can be created in two forms: using the byte() function or using the prefix “b”.
For example:

Result:
b'hello'b'Hello'
bytearray
Jaw bytearray() returns a bytearray object. It can convert objects to bytearray objects.
For example:

Result:
bytearray(b'\x00\x00\x00\x00')
memoryview
jaw memoryview() returns an object in memory view of a specified object.
For example:

Result:
As you have seen, some data types can also be implemented using their constructors. This same technique can be applied to any data type.
For example:

Result:
Hello, World!
4
3.14
(5+10j)
['Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye']
('Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye')
range(0, 10)
{'Learning': 'Programming', 'Language': 'Python', 'Day': 4}
{'apple', 'cherry', 'banana'}
frozenset({'banana', 'cherry', 'apple'})
True
False
b'\x00\x00\x00\x00'
bytearray(b'\x00\x00\x00\x00')
If you support and I see that the view of this article is high, I will do a few more articles comparing data types in python. So please support me.
Frequently asked questions
How many basic data types does Python have?
Python provides many basic data types, including numeric types (int, float, complex), string types (str), sequence types (list, tuple, range), map types (dict), set types (set, frozenset), Boolean types (bool), and binary types (bytes, bytearray, memoryview).
How to determine the data type of a variable in Python?
Use functions type(). For example: type(my_variable) will return the data type of the variable my_variable.
What is the difference between list and tuple in Python?
Both list and tuple are sequential data types, but list is mutable and tuple is immutable. This means you can add, remove, or modify elements in a list, but you can’t do that with a tuple.







