Python中str is not callable問題詳解及解決方法
問題提出:
在Python的程式碼,在運作過程中,碰到了一個錯誤訊息:
python程式碼:
def check_province_code(province, country): num = len(province) while num <3: province = ''.join([str(0),province]) num = num +1 return country + province
check_province_code('ab', '001') --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-44-02ec8a351cce> in <module>() ----> 1 check_province_code('ab', '001') <ipython-input-43-12db968aa80a> in check_province_code(province, country) 3 4 while num <3: ----> 5 province = ''.join([str(0),province]) 6 num = num +1 7 TypeError: 'str' object is not callable
>>> str(1233) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-45-afcef5460e92> in <module>() ----> 1 str(1233) TypeError: 'str' object is not callable