“LastIndexof Python” Kode Jawaban

Indeks terakhir dalam 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

LastIndexof 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

indeks dan indeks terakhir dalam 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

Jawaban yang mirip dengan “LastIndexof Python”

Pertanyaan yang mirip dengan “LastIndexof Python”

Lebih banyak jawaban terkait untuk “LastIndexof Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya