List operation error in PyCharm | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

15th Apr 2020, 6:13 PM
Sigitas S
Sigitas S - avatar
9 Answers
+ 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
15th Apr 2020, 6:53 PM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
16th Apr 2020, 8:05 PM
Lothar
Lothar - avatar
+ 3
Can you please put your entire code in playground and link it here? Thanks!
15th Apr 2020, 7:50 PM
Lothar
Lothar - avatar
+ 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
16th Apr 2020, 2:30 PM
Lothar
Lothar - avatar
+ 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
16th Apr 2020, 11:00 AM
Sigitas S
Sigitas S - avatar
+ 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.
16th Apr 2020, 5:47 PM
Sigitas S
Sigitas S - avatar
+ 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.
16th Apr 2020, 6:14 PM
Sigitas S
Sigitas S - avatar
- 1
Fill in the blanks to print "Yes" if the list contains 'z':
17th Apr 2020, 8:19 PM
Harish chandra maurya
Harish chandra maurya - avatar
- 1
Letters=['a,'b','z'] -"z"-letters: Print("Yes")
17th Apr 2020, 8:22 PM
Harish chandra maurya
Harish chandra maurya - avatar