In programming, data type is an important concept.
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:
Text | String |
---|---|
Numeric | int,float,complex |
Sequence | list,tuple,range |
Mapping | dict |
Set | set,frozenset |
Boolean | bool |
Binary | bytes,bytearray,memoryview |
Nonetype | None |
You can get the data type of any object by using the
type | Example | Getting Type | output |
---|---|---|---|
int | a = |
|
|
float | a = |
|
|
complex | a = |
|
|
str | a = |
|
|
list | a = [ |
|
|
tuple | a = ( |
|
|
range | a = |
|
|
dict | a = { |
|
|
set | a = { |
|
|
frozenset | a = |
|
|
bool | a = |
|
|
bytes | a = b |
|
|
bytesarray | a = |
|
|
memoryview | a = |
|
|
NoneType | a = |
|
|
If you want to specify the data type, you can use the following constructor functions
type | Example | Getting Type | output |
---|---|---|---|
int | a = |
|
|
float | a = |
|
|
complex | a = |
|
|
str | a = |
|
|
list | a = |
|
|
tuple | a = |
|
|
range | a = |
|
|
dict | a = |
|
|
set | a = |
|
|
frozenset | a = |
|
|
bool | a = |
|
|
bytes | a = |
|
|
bytesarray | a = |
|
|
memoryview | a = |
|
|