Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python get position of character in string

foo = "abcdefc"

# Using find()
foo.find('c')
# Output: 2
foo.find('g')
# Output: -1

# Using index()
# foo.index() is like foo.find(),
# But when the substring is not found, it raises an exception.
foo.index('h')
# ValueError: substring not found
 
PREVIOUS NEXT
Tagged: #python #position #character #string
ADD COMMENT
Topic
Name
6+5 =