python 3.10.4 Ubuntu 20.04 running python 3.10.4 spyder IDE Python 3.9.12 64-bit | Qt 5.9.7 | PyQt5 5.9.2 | Linux 5.15.0-47-generic
My python version in ubuntu and spyder are different. Does this cause the following problems?
I've run into two separate incidents on two separate sites where my IDE produced a different output to the one i the example.
B) This other website states that the following code:
fruits = ["apple", "grape", "orange", "guava", "banana"]
#Printing out the indexes of Apples and Banana
print("Indedx of Apple: " fruits.index("apple"))
print("Indedx of Banana: " fruits.index("banana"))
will produce the output: Indedx of Apple: 0 Indedx of Banana: 4
However, my IDE returns:
TypeError: can only concatenate str (not "int") to str
I made an error with question A and have removed it
CodePudding user response:
No, different versions of Python/IDEs/operation systems do not handle indexing differently.
For (A), please double check that you have not made some mistake when copying the code. For a start, it seems very unlikely that you are getting wor
because wor
is not even in the original string. Do you mean Wor
? Is it possible that you missed the final !
?
For (B), the website you copied from is wrong. Try the following:
fruits = ["apple", "grape", "orange", "guava", "banana"]
#Printing out the indexes of Apples and Banana
print("Indedx of Apple: " str(fruits.index("apple")))
print("Indedx of Banana: " str(fruits.index("banana")))