0% found this document useful (0 votes)
32 views4 pages

Class 9

The document discusses various data types in Python including lists, tuples, and their properties and methods. Lists are mutable and allow duplicate elements while preserving insertion order. Tuples are immutable collections of objects separated by commas.

Uploaded by

kunala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Class 9

The document discusses various data types in Python including lists, tuples, and their properties and methods. Lists are mutable and allow duplicate elements while preserving insertion order. Tuples are immutable collections of objects separated by commas.

Uploaded by

kunala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

List Data type:- if we want to represent a group of values as a single entity where

insertion orede to preseved and duplicate are allowed then we should go for list
data type.

i.Insertion order are preseved.


ii.hetrogeneous object are allowed.
iii.duplicates are allowed.
iv.Growable in nature.
v.values should be enclosed within squre bracket.

ex:- ex:-
x = eval(input('First number:'))
y = eval(input('second number'))i.low level programming lang.i.Insertion order are
preseved.
ii.hetrogeneous object are allowed.
iii.duplicates are allowed.
iv.Growable in nature.
v.values should be enclosed within squre bracket.
1.Arithmetic Operators
2.Relational or comparision operatos
3.Logical OperatosNote:- raw_input functi
print(x+y)

india nai tiobk batuibkeej ubd indian arngudfoaoddofhsdsoihfodhfvx jjsddgf


Note:- But in python3 we have only input() method and eaw_input() method is not
available.

python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.

Note:- raw_input function of python 2 is renamed as input() function in python3.


Methods of dictionary:-
clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault',
'update', 'values']
But in python3 we have only input() method and eaw_input() method is not available.

python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.

Note:- raw_input function of python 2 is renamed as input() function in python3.

10--->int
'scodeen'--->str
10.5--->float
But in python3 we have only input() method and eaw_input() method is not available.

python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.

Note:- raw_input function of python 2 is renamed as input() function in python3.

Note:- But in python3 we have only input() method and eaw_input() method is not
available.

python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.
Note:- raw_input function of python 2 is renamed as input() function in python3.

Output:-

we can write print() function to display output


l = [10,56.87,7+9j,True,'string',[1,2,3,4],10]
>>> l
[10, 56.87, (7+9j), True, 'string', [1, 2, 3, 4]]
>>>

Note:- But in python3 we have only input() method and eaw_input() method is not
available.

python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.

Note:- raw_input function of python 2 is renamed as input() function in python3.

list_methods:-

'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove',


'reverse', 'sort'

1.append:-used for appending and adding element to list.It is used to add element
to the last position of list.

ex:-
>>> l = [10,20,30,40]
>>> l.append(50)
>>> l
[10, 20, 30, 40, 50]

2.Insert:-Insert an element of specified position.

ex:-
>>> l = [10,20,40,50]
>>> l.insert(2,30)
>>> l
[10, 20, 30, 40, 50]

3.extend:-Add contents to list2 to the end of list 1.

>>> l1 = [10,20,30,40,50]
>>> l2 = [60,70,80,90,100]
>>> l1.extend(l2)
>>> l1
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

4.count:-calculate total occurrence of given element of list.


ex:-
>>> l = [1,2,3,1,1,1,2,3,3,1,2,2,3]
>>> len(l)
13
>>> l.count(1)
5
>>> l.count(2)
4
>>> l.count(3)
4
>>>

5. index:- Return the index of the first occurrance start and end index are not
nessary parameter.

ex:-
>>> l = [10,20,30,40,50,60,70]
>>> l.index(60)
5

6.clear:- clear the list and get a empty list.


ex:-
>>> l = [10,20,30,40,50,60,70,60]
>>> l.clear()
>>> l
[]

7.copy:- make a duplicate list using this method.


ex:-
>>> l = [10,20,30,40,50,60,70,60]
>>> s = l.copy()
>>> s
[10, 20, 30, 40, 50, 60, 70, 60]

8. pop():- delete the element from last position of the list.


ex:-
>>> l = [10,20,30,40,50,60]
>>> l.pop()
60
>>> l.pop(2)
30
>>> l
[10, 20, 40, 50]
>>>

9.remove():-Element to be deletedis mentrioned using list name and element.

ex:-
>>> l = [10,20,30,40,50,60]
>>> l.remove(20)
>>> l
[10, 30, 40, 50, 60]

10.sort:- converted accending order.

ex:-
>>> l = [1,9,7,8,0,6,8,3,7,11,99,77,90]
>>> l.sort()
>>> l
[0, 1, 3, 6, 7, 7, 8, 8, 9, 11, 77, 90, 99]

decending order.
>>> l = [1,9,7,8,0,6,8,3,7,11,99,77,90]
>>> l.sort(reverse= True)
>>> l
[99, 90, 77, 11, 9, 8, 8, 7, 7, 6, 3, 1, 0]
>>>
11.reverse:- just reverse the list

>>> l = [1,9,7,8,0,6,8,3,7,11,99,77,90]
>>> l.reverse()
>>> l
[90, 77, 99, 11, 7, 3, 8, 6, 0, 8, 7, 9, 1]
>>>

Tuple:-
A tuple is collection of python objects and it's separated by commas. In someways a
tuple is similar to a list in terms of indexing,but tuple immutable.

mutable:- Mutable means we can change or modify the element.

immutable:- immutable means we can not change or modify the element,we can just
watch the data,but cann't change it.

Note:- we can make tuple enclosed with parethesis :- ()

ex:-
>> t = (1,2,3)
>>> type(t)
<class 'tuple'>

You might also like