0% found this document useful (0 votes)
4 views

Data Handling Part 2

The document discusses mutable types in Python, such as lists, dictionaries, and sets, which can have their values changed in place. It explains the concept of variables as objects in Python, detailing their attributes: type, value, and id, along with examples of how to use built-in functions to retrieve this information. Additionally, it provides examples illustrating the behavior of sets and dictionaries in Python.

Uploaded by

ashugamerz1988
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Data Handling Part 2

The document discusses mutable types in Python, such as lists, dictionaries, and sets, which can have their values changed in place. It explains the concept of variables as objects in Python, detailing their attributes: type, value, and id, along with examples of how to use built-in functions to retrieve this information. Additionally, it provides examples illustrating the behavior of sets and dictionaries in Python.

Uploaded by

ashugamerz1988
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Data Handling

Std XI – Computer Science / Informatics


Practices
Part 2
Mutable types
The mutable types are those whose values can be
changed in place.
Example
Those are:
Lists >>>Chk =[2,4,6]
Dictionaries >>>id(Chk)
Sets 150195536
>>>Chk[1]=40
>>>id(Chk)
150195536
Variable Internals
Python is an object oriented language. Python
calls every entity that stores any values or any
type of data as an object.
An object is an entity that has certain properties
and that exhibit a certain type of behaviour .
Similarly , we can say that a variable is also an
object that refers to a value

Example- Integer values are objects, they hold


whole numbers only and they have infinite
precision (properties); they support all arithmetic
Every python object has three key attributes
associated to it:

1) The type of an object.


2) The value of an object
3) The id of an object
1) The type of an object: Built in function type()
returns the type of an object.

>>>a=4
>>>type(4)
<class ‘int’>
>>>type(a)
<class ‘int’>
2)The value of an object: It is the data-
item contained in the object. Using print
function we can display the value of an
object.
>>>a=4
>>>print(4)
4
>>>print(a)
4
3) The id of an object: The id of an object is
generally the memory location of the object.
id() function returns the id of the object.

>>>id(4)
30899132
>>>a=4
>>>id(a)
30899132
Sample code 308991
>>>id(4) 32
30899132
a 4
>>>a=4
>>>id(a)
30899132
308991
>>>b=5
20
>>>id(5) b 5
30899120
>>>id(b)
30899120 Note - While storing complex numbers id’s
are created differently, So Complex literal
>>>b=b-1
2.4j and complex variable say x having
>>>id(b) value 2.4j may have different id’s
30899132
Example 1
What is the output of the following code?

nset1={11,12,13,13}
print (nset1)

Output  {11,12,13}

Why did the code not print the output exactly as


the input?
Answer Because sets ignore the duplicate value ie. 13

Example 2
How are following two variables created using { }
different from one another?
V1={11,12,13,14}, V2={11:12,13:14}
Answer V1 is a set and V2 is a dictionary as it contains
key:value pairs.
>>>type(V1)
<class ‘set’>
>>>type(V2)
<class ‘dict’>

You might also like