TypeError: 'str' object is not callable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Traclo
    New Member
    • Oct 2007
    • 12

    TypeError: 'str' object is not callable

    I am doing a computer science project and I have to take a string that contains numbers, double each number individually and then return the doubled integers as one large string.

    I tried this code:

    def double_my_digit s(str):
    new_digits = []
    for c in str:
    b = int(c)
    a = b*2
    x = str(a)
    new_digits.appe nd(x)
    return "".join(new_dig its)

    But then it tells me that str object is not callable. I was wondering why I can't convert the new int into a string before appending to the list.

    Any help would be great! And thanks in advance.
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    Originally posted by Traclo
    I am doing a computer science project and I have to take a string that contains numbers, double each number individually and then return the doubled integers as one large string.

    I tried this code:

    def double_my_digit s(str):
    new_digits = []
    for c in str:
    b = int(c)
    a = b*2
    x = str(a)
    new_digits.appe nd(x)
    return "".join(new_dig its)

    But then it tells me that str object is not callable. I was wondering why I can't convert the new int into a string before appending to the list.

    Any help would be great! And thanks in advance.
    That's because the variable you pass in takes the place of the builtin function str(). Just make the varaible a different name. Be careful not to use builtin functions as varaible names.

    Comment

    Working...