Class 9
Class 9
insertion orede to preseved and duplicate are allowed then we should go for list
data type.
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)
python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.
python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.
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:- 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:-
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.
list_methods:-
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]
ex:-
>>> l = [10,20,40,50]
>>> l.insert(2,30)
>>> l
[10, 20, 30, 40, 50]
>>> 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]
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
ex:-
>>> l = [10,20,30,40,50,60]
>>> l.remove(20)
>>> l
[10, 30, 40, 50, 60]
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.
immutable:- immutable means we can not change or modify the element,we can just
watch the data,but cann't change it.
ex:-
>> t = (1,2,3)
>>> type(t)
<class 'tuple'>