Python Data Types

The data stored in the memory can be of many types. For example, a person’s name is stored as an alphabetic value, his age is stored in the numeric and his address is stored as an alphanumeric value. Sometimes, we also need to store answers only ‘yes’ or ‘no’, i.e., true or false. This type of data is known as Boolean data.

  • Numeric
  • Text
  • Sequence 
  • Mapped
  • Binary
  • Boolean
  • Set
  • NoneType
Numeric Data Typeint, float, complex
Text Data Typestring
Sequence DataTypelist, tuple, range
Mapped Data Typedict
Binary Data Typebytes, bytearray, memoryview
Boolean Data Typebool
Set DataTypeset, frozenset
None Data TypeNoneType

How do we get the Data Type?

We can get the data type of any object in Python by using the type() function.

a = 5
print(type(x))

OUTPUT

<class 'int'>

a = 5 
b = 1.23
c = 5j

#display the Value
print(a)
print(b)
print(c)

#print the data type
print(type(a)) 
print(type(b)) 
print(type(c)) 

OUTPUT

5
1.23
5j
<class 'int'>
<class 'float'>
<class 'complex'>

a = "Hello Wolrd"

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

Hello World
<class 'str'>

list

a = ["red", "blue", "black"]

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

['red', 'blue', 'black']
<class 'list'>

tuple

a = ("red", "blue", "black")

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

('red', 'blue', 'black')
<class 'list'>

range

a = range(8)

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

range(0, 8)
<class 'range'>

dict

a = {"name" : "Alex", "age" : 35}

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

{'name': 'Alex', 'age': 35}
<class 'dict'>

bytes

a = x"PythonCodeverse"

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

x'PythonCodeverse'
<class 'bytes'>

bytearray

a = bytearray(4)

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

bytearray(b'\x00\x00\x00\x00')
<class 'bytearray'>

memoryview

a = memoryview(bytes(5))

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

bytearray(b'\x00\x00\x00\x00\x00')
<class 'bytearray'>

a = True

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

True
<class 'bool'>

set

a = {'red', 'blue', 'green', 'black'}

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT


{'red', 'blue', 'green', 'black'}
<class 'set'>

frozenset

a = frozenset({'red', 'blue', 'green', 'black'})

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

frozenset({'red', 'blue', 'green', 'black'})
<class 'frozenset'>

a = None

#display the Value
print(a)

#print the data type
print(type(a)) 

OUTPUT

None
<class 'NoneType'>

You may also like...