DATA TYPES IN PYTHON

WHAT ARE THE DATA TYPES IN PYTHON?


Python has the following data types built-in by default. Variable can store data of different types as per requirements.

CategoriesData TypeExample
Textstrx = โ€œBe Happyโ€
Numericintx = 1
Numericfloatx = 3.5
Numericcomplexx = 1j
Sequencelistx = [โ€œAโ€, โ€œBโ€, โ€œCโ€]
Sequencetuplex = (โ€œAโ€, โ€œBโ€, โ€œCโ€)
Sequencerangex = range(6)
Mappingdictx = {โ€œfruitโ€ : โ€œAppleโ€, โ€œPriceโ€ : 200}
Setsetx = {โ€œAโ€, โ€œBโ€, โ€œCโ€}
Setfrozensetx = frozenset({โ€œAโ€, โ€œBโ€, โ€œCโ€})
Booleanboolx = True
Binarybytesx = bโ€Helloโ€
Binarybytearrayx = bytearray(6)
Binarymemoryviewx = memoryview(bytes(6))
NoneNoneTypex = 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
OrderedMutable-ChangeableUnique elements
ListYesYesNo
TupleYesNoNo
SetNoNoYes
DictionaryYesYesYes

Collection Datatypes in Python


Posted

in

Tags:

Comments

Leave a Reply