You are on page 1of 10

Data Types and Data Structures in Python : Summary

None boolean Numeric Sequences Sets Mappings

int ‘str’ {set} {dictionary


float bytes frozense }
complex bytearra t
y
[list]
(tuple)
(range)

Jamil Saudagar 12 of 75
Data Types and Data Structures in Python

Data Type Description


None Represents an object that does not contain any value. Similar to the ‘null’ object in Java or the
‘nothing’ object in VB.Net.
Bool Represents Boolean values i.e. True or False
Numeric There are 3 subtypes :
• int : Represents a number without a decimal point or the fraction part. It can hold negative as
well as positive numbers. Use the int() function to coerce a variable to this datatype
• float : Represents floating point numbers i.e. numbers that contain decimal values. It can also
be written in scientific notation; where we use e to represent the power of 10 (2.5 X 10 4 could
be written as 2.5e4). We use the float() function to convert a number to a float data type
• Complex numbers : A number that is written in the form of a + bj where a is a real and b an
imaginary number and j is the square root of -1. We use the complex() function to convert a
number to a complex value.

Jamil Saudagar 13 of 75
Data Types and Data Structures in Python - Examples
• Type the following statements in jupyter notebook to get a better understanding of the earlier discussed data
types and their conversions

Jamil Saudagar 14 of 75
Data Types and Data Structures in Python

Data Type Description


Sequences A sequence represents a group of elements or items. There are 6 types of sequences in Python :
• str : Text is represented as a string data type. It is nothing but a group of characters. It is either
enclosed in single or double quotes. We can also use triple double / single quotes if the
statement is spanning across multiple lines.
• bytes : represents a group of byte numbers between 0 and 255. Non-modifiable
• bytearray : This is the same as the bytes data type but the bytearray elements can be modified
and edited.
• list : This is similar to lists in C or Java. A list can hold different types of elements unlike an
array. Also, a list can grow dynamically unlike an array whose length is fixed. It is created using
square [] brackets. The elements of a list can be modified / edited.
• tuple : Is similar to a list but is only read-only i.e. cannot be modified. Also, it is created using
rounded () brackets.
• range : represents a sequence of numbers. Numbers in the range are non-modifiable. It is
typically used during looping. The parameters are entered in rounded () brackets.

Jamil Saudagar 15 of 75
Data Types and Data Structures in Python - Examples
• Type the following statements in jupyter notebook to get a better understanding of the earlier discussed data
types.

Jamil Saudagar 16 of 75
Data Types and Data Structures in Python - Examples
• Type the following statements in jupyter notebook to get a better understanding of the earlier discussed data
types.

Jamil Saudagar 17 of 75
Data Types and Data Structures in Python - Examples
• Type the following statements in jupyter notebook to get a better understanding of the earlier discussed data
types.

Jamil Saudagar 18 of 75
Data Types and Data Structures in Python

Data Type Description


Sets • A set is an unordered collection of elements i.e. the order of the elements is not maintained in the
sets. Hence element retrieval / slicing becomes difficult
• A set does not accept duplicate values i.e. duplicate values are rejected
• There are 2 types of the Sets data structure
• Set data type (modifiable)
• frozenset data type (non-modifiable)
Mapping Types • A map is a structure where values are stored as key value pairs, so that when the key is given we
(Dictionaries) can retrieve the associated value.
• The dict data type is an example of a map
• The key and the value need to be separated by a colon (:) and every pair should be separated by a
comma
• All the elements should be enclosed within curly brackets.

Jamil Saudagar 19 of 75
Data Types and Data Structures in Python - Examples
• Type the following statements in jupyter notebook to get a better understanding of the earlier discussed data
types.

Jamil Saudagar 20 of 75
Data Types and Data Structures in Python - Examples
• Type the following statements in jupyter notebook to get a better understanding of the earlier discussed data
types.

Jamil Saudagar 21 of 75

You might also like