Answers for "index in python"

43

python find index by value

>>> ["foo", "bar", "baz"].index("bar")
1
Posted by: Guest on November-19-2019
13

python string indexing

str = 'codegrepper'
# str[start:end:step]
#by default: start = 0, end = len(str), step = 1
print(str[:]) 		#codegrepper
print(str[::]) 		#codegrepper
print(str[5:]) 		#repper
print(str[:8]) 		#codegrep
print(str[::2]) 	#cdgepr
print(str[2:8]) 	#degrep
print(str[2:8:2]) 	#dge
#step < 0 : reverse
print(str[::-1]) 	#reppergedoc
print(str[::-3]) 	#rpgo
# str[start:end:-1]	means start from the end, go backward and stop at start
print(str[8:3:-1]) 	#pperg
Posted by: Guest on September-12-2020
8

find an index of an item in a list python

#Example List
list = ['apples', 'bannas', 'grapes']
#Use Known Entites In The List To Find The Index Of An Unknown Object
Index_Number_For_Bannas = list.index('apples')
#Print The Object
print(list[Index_Number_For_Bannas])
Posted by: Guest on January-02-2020
19

python index method

my_string = "Hello World!"

my_string.index("l") # outputs 2
# this method only outputs the index of the first "l" value in the string/list
Posted by: Guest on June-07-2020
1

What is the index in python

1) how to find index of a word in a string:
  my_string = "Hello World!"

  my_string.index("l")

2) how to find the first occurance of a word in a string:
  print(verse.index('and'))
  
  
 3)how to find the last occurance of a word in a string:
  print(verse.rindex('you'))
Posted by: Guest on July-18-2021
0

how to find index of list of list in python

[(i, colour.index(c))
 for i, colour in enumerate(colours)
 if c in colour]
Posted by: Guest on August-18-2020

Python Answers by Framework

Browse Popular Code Answers by Language