Python Forum
"my_value".index() inquiry...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"my_value".index() inquiry...
#1
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:
# 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
Reply


Messages In This Thread
"my_value".index() inquiry... - by RodNintendeaux - Jun-10-2017, 06:48 PM
RE: "my_value".index() inquiry... - by ichabod801 - Jun-10-2017, 06:57 PM
RE: "my_value".index() inquiry... - by snippsat - Jun-10-2017, 08:17 PM
RE: "my_value".index() inquiry... - by ichabod801 - Jun-10-2017, 08:18 PM
RE: "my_value".index() inquiry... - by ichabod801 - Jun-10-2017, 08:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  bluetooth device inquiry anne 0 2,381 Aug-01-2020, 12:24 AM
Last Post: anne

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020