“Индекс и последний индекс в Python” Ответ

Последний указатель в Python

# using rindex() 
test_string = "abcabcabc"
# using rindex() 
# to get last element occurrence 
res = test_string.rindex('c')  
# printing result 
print ("The index of last element occurrence: " + str(res))

OUTPUT:
  The index of last element occurrence: 8
asta p

индексировать Python первым и последним

l = [1,2,3,4,5]
l[::len(l)-1]
Sleepy Shark

Индекс и последний индекс в Python

# To get first and last index of list or string
list_a = [1,2,3,4]
first_index = list_a[0] # 1
last_index = list_a[-1] # 4
str_a = "abc"
first_index_str = str_a[0] # a
last_index_str = str_a[-1] # c

# To find first and last index of char in string
str_b = "abcabcdec"
first_index_of_c = str_b.index("c") # 2
last_index_of_c = str_b.rindex("c") # 8
Sad Santa

Ответы похожие на “Индекс и последний индекс в Python”

Вопросы похожие на “Индекс и последний индекс в Python”

Смотреть популярные ответы по языку

Смотреть другие языки программирования