.


:




:

































 

 

 

 





.

. . .

>>> a_list = ['a', 'b', 'new', 'mpilgrim', 'new']
>>> a_list[1]
'b'
>>> del a_list[1] ①
>>> a_list
['a', 'new', 'mpilgrim', 'new']
>>> a_list[1] ②
'new'

del .
1 1, . , , .

? .

>>> a_list.remove('new') ①
>>> a_list
['a', 'mpilgrim', 'new']
>>> a_list.remove('new') ②
>>> a_list
['a', 'mpilgrim']
>>> a_list.remove('new')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: list.remove(x): x not in list

:

( ):

"<stdin>", 1, <>

ValueError: list.remove(x): x

remove(). remove() . , , , , . .
remove() , , , , .

:

pop(). pop() , .

>>> a_list = ['a', 'b', 'new', 'mpilgrim']
>>> a_list.pop() ①
'mpilgrim'
>>> a_list
['a', 'b', 'new']
>>> a_list.pop(1) ②
'b'
>>> a_list
['a', 'new']
>>> a_list.pop()
'new'
>>> a_list.pop()
'a'
>>> a_list.pop() ③
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: pop from empty list

:

( ):

"<stdin>", 1, <>

IndexError: pop

pop() , .
pop() . . , , . .
pop() .

 

pop() pop() Perl. . Perl shift(), . Python a_list.pop(0).




:


: 2016-11-18; !; : 433 |


:

:

: , .
==> ...

1822 - | 1426 -


© 2015-2024 lektsii.org - -

: 0.009 .