DATA HANDLING
DATATYPES: Data can be many types: Character, integer, real, string etc. Anything enclosed in
quotes represents string data in python. Number without fractions represents integer data. Number
with fractions represents floating point numbers.
Python offers following built-in core data types:
1. Numbers
2. String
3. List
4. Tuple
5. Dictionary
Number: The number in python has following core datatypes:
(i) Integers Eg: 5 , 39, 1958 etc
(ii) Floating point numbers Eg: 3.14, 0.0521, 147.9215
(iii) Complex number Eg: A+Bi where i is the imaginary number
Strings: A string data type lets you hold string data, i.e. any number of valid character into a set of
quotation marks.
Eg: “abcd” , “1345”, “&&&&”
String as a sequence of characters: A python string is a sequence of charactersand each character
can be individually accessed using its index.
LISTS & TUPLES
The list and tuples are python‟s compound data types. They are basically the same type with one
difference. List can be changed or modified (i.e. mutable) but tuples cannot be changed or
modified (i.e. immutable).
LISTS: A list in python represents a list of comma separated values of any data types between
square brackets.
Eg: [ 1, 2, 3, 4] [„a‟, „e‟, „i‟, „o‟, „u‟] [„Neha‟, 102 , 79.5]
Assigning a list to a variable
>>> a = [ 1, 2 , 3 , 4 , 5]
>>> a
[ 1, 2 , 3 , 4 , 5]
>>> print(a)
[ 1, 2 , 3 , 4 , 5]
To change the first value in list
>>> a [0] = 10
>>> a [10 , 2 , 3 , 4 , 5 ]
To change the third value in list
>>> a [2] = 20
>>> a [10 , 2 , 20 , 4 , 5 ]
TUPLES
Tuples are those list which cannot be changed i.e. are not modifiable. Tuples are represented as list
of comma-separated values of any data types with curly brackets.
Eg: p = (1, 2 , 3 , 4 , 5)
q = („a‟ , „e‟, „i‟, „o‟, „u‟)
r = (7, 8 , 9, „A‟, „B‟, „C‟)
DICTIONARY
Dictionary data type is an unordered set of comma-separated key : value pairs, within { }, with the
requirements that within a dictionary , no two keys can be same (i.e. there are unique keys within a
dictionary)
MUTABLE & IMMUTABLE TYPES
The python data objects can be broadly categorized into two: mutable and immutable types, in
simple words changeable or modifiable (mutable) and non-modifiable types (immutable)
IMMUTABLE TYPES:
The immutable types are those that can never change their values in place. In python, the following
types are immutable: integers, floating point numbers, Boolean, strings, tuples.
For Eg: p=5
q=p
r=5
You can check / confirm it using id( ). The id( ) returns the memory address to which a variable is
referencing.
when the next set of statements executes, i.e.
p=10
r=7
q=r
MUTABLE TYPES
The mutable types are those whose values can be changed in place. Only three data types are
mutable in python. These are lists, dictionaries and sets.
************************TO BE CONTINUED… ***********************