Data Handing in Python
Data Handing in Python
Class 11
Chapter- 7
Introduction
• In this chapter we will learn data
types, variables, operators and
expression in detail.
• Python has a predefined set of data
types to handle the data in a program.
• We can store any type of data in
Python.
DATA TYPES
• Data can be of any type like- character, integer,
real, string.
• Anything enclosed in “ “ is considered as string in
Python.
• Any whole value is an integer value.
• Any value with fraction part is a real value.
• True
I. or False value
Number specifies
(int like10, boolean
5) (float value.(complex
like 3.5, 302.24)
• Python
s supportslike
following
3+5i) (likecore data
“pankaj”, types-
‘pankaj’, ‘a’, “a” )
II. String like [3,4,5,”pankaj”] its elements are
III. List Mutable. like(3,4,5,”pankaj”) its
IV. Tuple elements are immutable.
V. Dictionar like {‘a’:1, ‘e’:2, ‘I’:3, ‘o’:4, ‘u’:5} where
y a,e,i,o,u
are keys
and 1,2,3,4,5 are their values.
CORE DATA TYPES
Graphical
View
CORE
DATA TYPE
Floating
Integer Complex String Tuple List Dictionary
Point
Boolean
Mutable and Immutable
• TypesData Objects are categorized in two
In Python,
types-
• Mutable (Changeable)
• Immutable (Non-Changeable)
Look at following statements carefully-
p = 10
q=p they will represent 10, 10, 10
r = 10
Now, try to change the
rvalues-
= 7 p = 17 did the values actually
q =9 change?
Answer is
NO.
Because here values are objects and p, q, r are their
reference name. To understand it, lets see the next slide.
Variables and Values
An important fact to know is-
– In Python, values are actually objects.
– And their variable names are actually their reference
names.
Suppose we assign 10 to a
variable A. A = 10
Here, value 10 is an object and A
is its reference name.
10
Reference Object
variable
Variables and Values
If we assign 10 to a
variable B, B will refer to
same object.
Here, we have two 10
• Immutable (Non-Changeable)
– integers, floats, Booleans, strings and tuples.
Variable
Internals
The
• Pay attention Type
to the of an Object
following command-
The ID of an Object
• Pay attention to the following command-
www.pythontrends.wordpress.
com