+ 4

cant solve this

>>> letters=('p','t','z','j','u','elem') >>> if 'elem' in letters: ... letters.remove('elem') ... Traceback (most recent call last): File "<stdin>", line 2, in <module> AttributeError: 'tuple' object has no attribute 'remove'

14th Sep 2018, 3:11 PM
tarok
tarok - avatar
4 Réponses
+ 13
The round brackets indicate that letters is a tuple, not a list. A tuple is immutable, so you can't remove items from it. To declare a list, use letters=list(('p','t','z','j','u','elem')) or simply letters=['p','t','z','j','u','elem'].
14th Sep 2018, 3:19 PM
Anna
Anna - avatar
+ 4
remove is the method for list not for tuple you are using in tuple. letters=['p','t','z','j','u','elem'] if 'elem' in letters: letters.remove('elem')
14th Sep 2018, 4:30 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
tarok bro try using list ... not in tuple will produce error because u cannot change any values or removing it;)😎😎🌏Ty
14th Sep 2018, 4:44 PM
Sri Raman Prasad
0
the curve brackets indicate it's a type, change to block brackets and the work is done..
20th Sep 2018, 12:34 PM
STANLEY EZE
STANLEY EZE - avatar