List operation error in PyCharm | Sololearn: Learn to code for FREE!

+2

List operation error in PyCharm

B = "Python is a best" C = list(B) print(C) It's run on Sololearn and Python IDLE, but I get error on Pycharm (TypeError: 'str' object is not callable)? Why? Any problem with Pycharm?

4/15/2020 6:13:40 PM

Sigitas S

9 Answers

New Answer

+4

Is this the entire code or just a snippet? If you are possibly redefining str somewhere else in your source, then you'd get this error. example: str = "python!" ... ... b = "python is the best" c = b print(c) #error you redefined the str object

+4

maklaudas, thanks for sharing your latest sample. In the last section a variable is named "list" and a string is assigned. This should not be done! "list" is a class from python, and using it for other purposes can cause unexpected problems. If you are not sure if a variable name can be used, you can go to the python console. Type e.g. help("list"), and you will see if this name is used in python or not. Or you can use an underscore that you append at the end of the variable name like list_. This is a valid identifyer that can be used without pain.

+3

Can you please put your entire code in playground and link it here? Thanks!

+3

I have tested your code on several os platforms on other online IDE's and several regular IDE's. The code does run without any error. So i have my doubt that we have all information we need. I can give you a sample, to provoke the mentioned error message. str ="Python is the best" B = list(str) print (B) print(str(24)) What happens here is, that i used a variable name "str", that is also used for the built-in function in python. So if i use a very simple expression "print(str(24))" (that also uses str()), that should work without any problem, i get the message: print(str(24)) TypeError: 'str' object is not callable

+2

Lothar that whole code. So why I don't understand why it's running in IDLE and Sololearn, but not in Pycharm https://code.sololearn.com/c6fXBYDsK1ne/?ref=app

+1

Thank you guys. I'm new and just learning Python. I'm practising write codes, and looks like I used that phrase 'I love Python' and 'I like Python' with different variables few times before. Yes, when O tried to input code in empty Pycharm file it is works very well, like on IDLE or Sololearn. So everything alright. Thank a lot :) That is lesson, don't use same phrase.

+1

https://code.sololearn.com/ceTD5qk9JNJ4/#py That one 3 codes which one I played. First code 'xx works always, second 'tt' works just if last code will be after him (like in this example), but if you move last code in first or second place, 'tt' code won't work.

-1

Fill in the blanks to print "Yes" if the list contains 'z':

-1

Letters=['a,'b','z'] -"z"-letters: Print("Yes")