In [2]:
l = [1,2,3, 5.5, 'python']

In [3]:
l


Out[3]:
[1, 2, 3, 5.5, 'python']

In [4]:
print l.append.__doc__


L.append(object) -- append object to end

In [6]:
print l.append('class')
print l


None
[1, 2, 3, 5.5, 'python', 'class', 'class']

In [7]:
print l.insert.__doc__


L.insert(index, object) -- insert object before index

In [8]:
print help(l.insert)


Help on built-in function insert:

insert(...)
    L.insert(index, object) -- insert object before index

None

In [9]:
l.insert(2, 'nag')

In [10]:
print l


[1, 2, 'nag', 3, 5.5, 'python', 'class', 'class']

In [11]:
print l.extend.__doc__


L.extend(iterable) -- extend list by appending elements from the iterable

In [12]:
a = [10,11,12]
l.extend(a)
print l


[1, 2, 'nag', 3, 5.5, 'python', 'class', 'class', 10, 11, 12]

In [13]:
l.extend(5)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-29a21926453b> in <module>()
----> 1 l.extend(5)

TypeError: 'int' object is not iterable

In [16]:
l.extend((5,7))

In [17]:
for x in l:
    print x
print "exited from loop"


1
2
nag
3
5.5
python
class
class
10
11
12
5
7
exited from loop

In [18]:
a


Out[18]:
[10, 11, 12]

In [19]:
for x in a:
    b = x**2
    print b
print "existed from loop"


100
121
144
existed from loop

In [20]:
for x in "python":
    print x


p
y
t
h
o
n

In [21]:
for i in a:
    print a


[10, 11, 12]
[10, 11, 12]
[10, 11, 12]

In [22]:
for i in a:
    print "nag"


nag
nag
nag

In [23]:
range(10)


Out[23]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [24]:
range(2,10)


Out[24]:
[2, 3, 4, 5, 6, 7, 8, 9]

In [27]:
range(2,10,3)


Out[27]:
[2, 5, 8]

In [28]:
a


Out[28]:
[10, 11, 12]

In [29]:
a.append([1,2,3])
print a


[10, 11, 12, [1, 2, 3]]

In [30]:
a[3]


Out[30]:
[1, 2, 3]

In [31]:
l


Out[31]:
[1, 2, 'nag', 3, 5.5, 'python', 'class', 'class', 10, 11, 12, 5, 7]

In [32]:
print l.pop.__doc__


L.pop([index]) -> item -- remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.

In [33]:
print help(l.pop)


Help on built-in function pop:

pop(...)
    L.pop([index]) -> item -- remove and return item at index (default last).
    Raises IndexError if list is empty or index is out of range.

None

In [34]:
l


Out[34]:
[1, 2, 'nag', 3, 5.5, 'python', 'class', 'class', 10, 11, 12, 5, 7]

In [35]:
x = l.pop()
print x
print l


7
[1, 2, 'nag', 3, 5.5, 'python', 'class', 'class', 10, 11, 12, 5]

In [36]:
print l.pop(2)
print l


nag
[1, 2, 3, 5.5, 'python', 'class', 'class', 10, 11, 12, 5]

In [37]:
print l.remove.__doc__


L.remove(value) -- remove first occurrence of value.
Raises ValueError if the value is not present.

In [38]:
l.append(3)

In [39]:
l


Out[39]:
[1, 2, 3, 5.5, 'python', 'class', 'class', 10, 11, 12, 5, 3]

In [40]:
l.remove(3)
print l


[1, 2, 5.5, 'python', 'class', 'class', 10, 11, 12, 5, 3]

In [41]:
l.remove(100)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-41-97ac9c8b213c> in <module>()
----> 1 l.remove(100)

ValueError: list.remove(x): x not in list

In [42]:
l.pop(100)


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-42-593dc6fd75d7> in <module>()
----> 1 l.pop(100)

IndexError: pop index out of range

In [43]:
l.pop(1,2)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-43-46da867bc3bc> in <module>()
----> 1 l.pop(1,2)

TypeError: pop() takes at most 1 argument (2 given)

In [44]:
var = 10

In [45]:
print var


10

In [46]:
del var

In [47]:
print var


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-47-7d9e14424534> in <module>()
----> 1 print var

NameError: name 'var' is not defined

In [48]:
l


Out[48]:
[1, 2, 5.5, 'python', 'class', 'class', 10, 11, 12, 5, 3]

In [49]:
del l[-1]

In [50]:
print l


[1, 2, 5.5, 'python', 'class', 'class', 10, 11, 12, 5]

In [51]:
a


Out[51]:
[10, 11, 12, [1, 2, 3]]

In [52]:
del a

In [53]:
print a


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-53-da1608c9d425> in <module>()
----> 1 print a

NameError: name 'a' is not defined

In [54]:
l


Out[54]:
[1, 2, 5.5, 'python', 'class', 'class', 10, 11, 12, 5]

In [55]:
l.count.__doc__


Out[55]:
'L.count(value) -> integer -- return number of occurrences of value'

In [56]:
print l.count('class')


2

In [57]:
x = l.count('class')
print x


2

In [58]:
l.count(100)


Out[58]:
0

In [59]:
l.index.__doc__


Out[59]:
'L.index(value, [start, [stop]]) -> integer -- return first index of value.\nRaises ValueError if the value is not present.'

In [60]:
l.index(5)


Out[60]:
9

In [61]:
l


Out[61]:
[1, 2, 5.5, 'python', 'class', 'class', 10, 11, 12, 5]

In [62]:
l.index(100)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-62-42afed85a69b> in <module>()
----> 1 l.index(100)

ValueError: 100 is not in list

In [63]:
l.index.__doc__


Out[63]:
'L.index(value, [start, [stop]]) -> integer -- return first index of value.\nRaises ValueError if the value is not present.'

In [64]:
l


Out[64]:
[1, 2, 5.5, 'python', 'class', 'class', 10, 11, 12, 5]

In [65]:
l.index(2, 3)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-65-28d6e25954a7> in <module>()
----> 1 l.index(2, 3)

ValueError: 2 is not in list

In [66]:
l.index(10, 3)


Out[66]:
6

In [68]:
l.index(10, 3, 7)


Out[68]:
6

In [69]:
l.append(10)

In [70]:
l


Out[70]:
[1, 2, 5.5, 'python', 'class', 'class', 10, 11, 12, 5, 10]

In [71]:
x = l.index(10)

In [72]:
x


Out[72]:
6

In [73]:
x = l.index(10, x+1)

In [74]:
print x


10

In [75]:
l.pop(x)


Out[75]:
10

In [76]:
l.sort.__doc__


Out[76]:
'L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;\ncmp(x, y) -> -1, 0, 1'

In [77]:
l.sort()

In [78]:
l


Out[78]:
[1, 2, 5, 5.5, 10, 11, 12, 'class', 'class', 'python']

In [79]:
l.append('Python')

In [80]:
l


Out[80]:
[1, 2, 5, 5.5, 10, 11, 12, 'class', 'class', 'python', 'Python']

In [81]:
l.sort()

In [82]:
l


Out[82]:
[1, 2, 5, 5.5, 10, 11, 12, 'Python', 'class', 'class', 'python']

In [83]:
l.reverse()

In [84]:
l


Out[84]:
['python', 'class', 'class', 'Python', 12, 11, 10, 5.5, 5, 2, 1]

In [ ]: