• Register
1 vote
796 views

Problem:

I am newbee in python program and I wrote this code:

def DeletChar(e, b) : 
      
    counts = e.count(b) 
     
  
       
    while counts : 
                 
        e.remove(b) 
  
        counts -= 1
   
 
      
    print(e) 
  
if __name__ == '__main__' : 
      
    e = "LOVENOTLOLOVE"
    DeletChar(e,'L') 

But this code gives me the following error:

Traceback (most recent call last):
  File "proc.py", line 20, in <module>
    DeletChar(e,'L') 
  File "main.py", line 9, in DeletChar
    e.remove(b) 
AttributeError: 'str' object has no attribute 'remove'

Can anyone help me out to fix this problem?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote

Answer:

In your problem you are just counting the “e” but it do not belong to a list or it do not carry any value or any attribute thats why you are getting this error message. You should write your code like:

def DeletChar(e, b) : 
      
    counts = e.count(b) 
     
    e = list(e) 
       
    while counts : 
                 
        e.remove(b) 
  
        counts -= 1
   
 
      
    print(e) 
  
if __name__ == '__main__' : 
      
    e = "LOVENOTLOLOVE"
    DeletChar(e,'L') 

Hope you understand and this may solve your problem

11 6 4
34,950 points

Related questions

0 votes
1 answer 837 views
837 views
Python 3.3.2 import json & urllib.request Json [{"link":"","orderid":"100000222"}, {"link":"","orderid":"100000222"}, {"link":"","orderid":"100000222"}] print(response.info()) Date: Sun, 20 Oct 2013 07:06:51 GMT Server: Apache X-Powered-By: PHP/5.4.12 Content ... line 271, in load return loads(fp.read(), AttributeError: 'str' object has no attribute 'read' >>> . Any idea how i can fix this issue?
asked Oct 25, 2020 psandprop 2.4k points
0 votes
1 answer 898 views
898 views
Problem: I am working on the sort function but while doing a small problem I am getting a error can you please what I am doing wrong,Program that takes a list of student name and sorts them to create a class roll number. The list of names will be given on line separated by ... item.sort(lambda x, y: cmp(x.lower(),y.lower())) print(item) AttributeError: 'str' object has no attribute 'sort'" Error"
asked Jun 9, 2020 Gavin 15.3k points
0 votes
1 answer 4 views
4 views
Problem: I have been trying to solve this problem, please help > Attributeerror: 'series' object has no attribute 'sort'
asked 2 days ago Junia Phoebe 15.3k points
0 votes
1 answer 18 views
18 views
Problem: Can anyone help me with this problem? > Attributeerror: 'tensor' object has no attribute 'numpy'
asked 3 days ago Junia Phoebe 15.3k points
0 votes
1 answer 2 views
2 views
Problem: Where can I find a solution for this? >Attributeerror: 'nonetype' object has no attribute 'lower'
asked 4 days ago Sawyer Parviz 13.5k points
0 votes
1 answer 32 views
32 views
Problem: I'm trying to delete the first 24 rows of my pandas dataframe. Searching on the web has led me to believe that the best way to do this is by using the pandas 'drop' function. However, whenever I try to use it, I get the error: AttributeError: 'numpy. ... should do to delete the first 24 rows of my dataframe. (This was all done using Python 3 on a Jupyter notebook on my local machine)
asked May 3 muktaa 34.6k points
1 vote
1 answer 22 views
22 views
Problem: I am working on a dictionary but I get an : Attributeerror: 'nonetype' object has no attribute 'update'.
asked May 1 PkGuy 23.5k points
1 vote
2 answers 8 views
8 views
Problem: I have a string where I find this error: Attributeerror: 'nonetype' object has no attribute 'groups'.
asked Apr 25 PkGuy 23.5k 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 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