In the example below, how do I list all (index numbers) of the existing elements of the array because using the index () without passing one or more arguments generates an error: TypeError: index expected at least 1 argument, got 0. Remembering that I need to list all indexes !
letter = ['a', 'e', 'i', 'o', 'i', 'u']
output = letter.index()
print(output)
spam = ['a', 'e', 'i', 'o', 'i', 'u']
for idx, char in enumerate(spam):
print(f'{idx} --> {char}')
Output:
0 --> a
1 --> e
2 --> i
3 --> o
4 --> i
5 --> u
Now the question is do you really need the indexes.
(Feb-26-2021, 05:53 AM)buran Wrote: [ -> ]spam = ['a', 'e', 'i', 'o', 'i', 'u']
for idx, char in enumerate(spam):
print(f'{idx} --> {char}')
Output:
0 --> a
1 --> e
2 --> i
3 --> o
4 --> i
5 --> u
Now the question is do you really need the indexes.
Yes, I thank buran and within the context how do I access a certain value from within the array by idx?
This is a really basic thing and it's surprising you're having to ask. It's easily found in any introductory materials on the language, e.g
the Python tutorial.