.


:




:

































 

 

 

 





, .

, , if:

>>> def is_it_true(anything):
... if anything:
... print(", ")
... else:
... print(", ")
...
>>> is_it_true([]) ①
,
>>> is_it_true(['a']) ②
,
>>> is_it_true([False]) ③
,

.
, , .
, , . .

. .

>>> a_tuple = ("a", "b", "mpilgrim", "z", "example") ①
>>> a_tuple
('a', 'b', 'mpilgrim', 'z', 'example')
>>> a_tuple[0] ②
'a'
>>> a_tuple[-1] ③
'example'
>>> a_tuple[1:3] ④
('b', 'mpilgrim')

, , , , .
, . , , a_tuple[0].
, .
(slicing) . , ; , .

, . , . , , . , append(), extend(), insert(), remove(), pop(). . ( ), , ( ), ... , .

#
>>> a_tuple
('a', 'b', 'mpilgrim', 'z', 'example')
>>> a_tuple.append("new") ①
Traceback (innermost last):
File "<interactive input>", line 1, in?
AttributeError: 'tuple' object has no attribute 'append'
>>> a_tuple.remove("z") ②
Traceback (innermost last):
File "<interactive input>", line 1, in?
AttributeError: 'tuple' object has no attribute 'remove'
>>> a_tuple.index("example") ③
4
>>> "z" in a_tuple ④
True

:

( ):

"< >", 1, ?

AttributeError: 'tuple' '<>'

. append() extend().
. remove() pop().
, .
in, .

?

  • , . , , .
  • , , . assert, , , ( ), .
  • (, , , , , ). , .
. tuple() , list() . , tuple() , list() .




:


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


:

:

, , .
==> ...

1499 - | 1414 -


© 2015-2024 lektsii.org - -

: 0.011 .