• Register
1 vote
937 views

Problem:

Hello all,

I have started learning python recently. I installed python 3.2 on my Linux machine. I come to know about a function .clear() that clears the value inside a list. I am trying to clear the values of my list but it’s not working for my case, and returning an error  What could be the reason behind it? Please pull me up you have the legit answer. Thanks.
Find my sample code snippet below

>>> list = [10, 20, 30, 40, 50, 60, 70]
>>> list.clear()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'clear'

 

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

The reason behind it is very simple. The list.clear() function is compatible with only for python 3.3 and later version. It was introduced in python 3.3 version. To fix the error you may install the latest python version. If you are too lazy to do that you can use del list [ : ] instead.

Thanks

13 9 6
94,260 points

Related questions

0 votes
1 answer 19 views
19 views
Problem: Please let me know any solution regarding this .. Attributeerror: 'list' object has no attribute 'shape'
asked Apr 26 Ifra 37.2k points
0 votes
1 answer 51 views
51 views
Problem: please help me to fix this : Attributeerror: 'list' object has no attribute 'keys'.
asked Mar 6 Wafa Abu Yousef 6.1k points
1 vote
1 answer 4K views
4K views
Problem: I have a dictionary with some users' data in it. Trying to use the dictionary to call with .append() function but it throws an error that says attributeerror: 'list' object has no attribute 'keys' But I haven&rsquo;t declared it as a list in my program. Where am I doing wrong? Could ... = {} n = 0 for i in dict.keys(): new[i] = entry(n) n += 1 dict.append(new) Many thanks for your help.
asked Apr 5, 2020 Gavin 15.3k points
0 votes
1 answer 36 views
36 views
Problem: Hello! I am a new programmer and I recently learned the concept of container types in Python. I have never worked with dictionaries and lists before. I tried running the following program in which I am adding the items into a dictionary through a list: lst = ... but I am unable to understand why it is showing an error with the dictionary. Could someone please help me sort this error out?
asked Apr 6 Code Learner 9.9k points
0 votes
1 answer 5 views
5 views
Problem: What is causing this error? > Attributeerror: 'module' object has no attribute 'smtp'
asked 2 days ago Junia Phoebe 15.3k points
0 votes
1 answer 10 views
10 views
Problem: Please solve it &hellip; Because I am unable to find out the solution .. attributeerror: 'generator' object has no attribute 'next'
asked Apr 21 Ifra 37.2k points
0 votes
1 answer 44 views
44 views
Problem: My friend's computer showing this error by two to three days,he tried to fix but he can't able to, then he requested me to help but i am a beginner in this field then i think i have to post here my problem by which i can got my answer, can anyone help me out?
asked Apr 4 niyatiry 3.9k points
0 votes
1 answer 42 views
42 views
Problem : any expert to help me with this : Attributeerror: '_io.textiowrapper' object has no attribute 'split'..
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 298 views
298 views
Problem: I want to count the number of times a word is being repeated in the review string I am reading the csv file and storing it in a python dataframe using the below line reviews = pd.read_csv("amazon_baby.csv") The code in the below lines work when I apply it to a single review. print reviews["review"][1] a = reviews["review"][1].split("disappointed") print a b = len(a) print b
asked Feb 23 Mashhoodch 13k points
0 votes
1 answer 84 views
84 views
Problem: attributeerror: 'series' object has no attribute 'reshape'
asked Feb 18 charles mathews 5.5k points