Python list


#1

animals = [“ant”, “bat”, “cat”]
print animals.index(“bat”)

why this code given in the modules works right python IDLE or pycharm but it works correctly in codecademy ide


#2

Hello @designrockstar36837, what you mean it works right with Python IDLE or PyCharm?

You have to take into account PyCharm requires a Python interpreter to work, so probably you have installed Python 3 version on your PC, while Codecademy uses Python 2. Hence, you print statement requires a parentheses to work:

# Python3 Code
animals = ["ant", "bat", "cat"]
print(animals.index("bat"))

#3

Ya I mean it showed syntax error in of charm and python idle


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.