Python has the following data types built-in by default. Variable can store data of different types as per requirements.
Categories | Data Type | Example |
Text | str | x = โBe Happyโ |
Numeric | int | x = 1 |
Numeric | float | x = 3.5 |
Numeric | complex | x = 1j |
Sequence | list | x = [โAโ, โBโ, โCโ] |
Sequence | tuple | x = (โAโ, โBโ, โCโ) |
Sequence | range | x = range(6) |
Mapping | dict | x = {โfruitโ : โAppleโ, โPriceโ : 200} |
Set | set | x = {โAโ, โBโ, โCโ} |
Set | frozenset | x = frozenset({โAโ, โBโ, โCโ}) |
Boolean | bool | x = True |
Binary | bytes | x = bโHelloโ |
Binary | bytearray | x = bytearray(6) |
Binary | memoryview | x = memoryview(bytes(6)) |
None | NoneType | x = None |
PYTHON DATA TYPES
To get the data type of any object we can use the type() function in Python.
Example-
print (type(x))
PYTHON COLLECTIONS (ARRAYS)
There are four collection data types in the Python programming language:
List
List is a collection which is ordered and changeable. Allows duplicate members.
Tuple
Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
Set
Set is a collection which is unordered, unchangeable, and unindexed. No duplicate members.
Set items are unchangeable, but you can remove and/or add items.
Dictionary
is a collection which is ordered and changeable. No duplicate members.
PROPERTIES OF COLLECTION DATATYPES IN PYTHON
Collection DataTypes | Ordered | Mutable-Changeable | Unique elements |
List | Yes | Yes | No |
Tuple | Yes | No | No |
Set | No | No | Yes |
Dictionary | Yes | Yes | Yes |
Collection Datatypes in Python
Leave a Reply