2.3 Data Types in Python
2.3 Data Types in Python
Data type identifies the type of data values a variable can hold and the
operations that can be performed on that data.
Note:
In order to determine the data type of the variable, we can use the built-
in function type()
3
Data types in Python
4
Data types in Python: Numeric
Number data type stores numerical values only. It is further classified into
three different types:
- int
- float and
- complex
Variables of simple data types like integers, float, boolean, etc., hold single
values. But such variables are not useful to hold a long list of information, for
example,
- names of the months in a year,
- names of students in a class,
- names and numbers in a phone book or
- the list of artefacts in a museum.
For this, Python provides data types like tuples, lists, dictionaries and sets.
7
Data types in Python: Sequence
e.g.) “de4dr”, ‘fre67’ [5, 3.4, "New Delhi", "20C", 45] (10, 20, "Apple", 3.4, 'a')
9
Data types in Python: Set
Note:
A set is similar to list, except that
it cannot have duplicate entries
It is immutable, and
It is unordered
10
Data types in Python: None
None is a special data type with a single value. It is used to signify the
absence of value in a situation.
Mutable: Variables whose values can be changed after they are created
and assigned are called mutable
E.g.) Lists, dictionary, etc.
Immutable: Variables whose values cannot be changed after they are
created and assigned are called immutable.
E.g.) Numbers, strings, tuples etc.
Summary
15
Assignment
Which data type will be used to represent the following data values and
why?
a) Number of months in a year b) Resident of Delhi or not
c) Mobile number d) Pocket money
e) Volume of a sphere f) Perimeter of a square
g) Name of the student h) Address of the student