Jun-10-2017, 06:48 PM
So I am learning this .index() thingy and know how to use it for a single character in a string, but I am running into errors trying to attempt to index multiple characters that match. For instance, I am running this code:
I have tried all types of coding setups and failed; and searching the web leads me nowhere. Can anyone help me understand this and the limitations (if any) Python has in this scenario?
Synopsis: I am trying to pull all "a" locations for output >>> 0, 2, 4 using .string(). Can I pull all three? Or am I limited to just the first "a" in a string?
Stuck in a loop of my own errors in learning,
-Rod
# test code (alabaster, can I index all three a's?) "alabaster".index("a")It outputs 0, for the first a in the string. But what about 2 and 4? I can run:
my_value = alabaster my_value[0] my_value[2] my_value[4]...to pull the a's myself, but can I simply call the string of all a's up front?
I have tried all types of coding setups and failed; and searching the web leads me nowhere. Can anyone help me understand this and the limitations (if any) Python has in this scenario?
Synopsis: I am trying to pull all "a" locations for output >>> 0, 2, 4 using .string(). Can I pull all three? Or am I limited to just the first "a" in a string?
Stuck in a loop of my own errors in learning,
-Rod