python find first character in string code example

Example 1: how to find the location of a character in a string in python

>>> myString = 'Position of a character'
>>> myString.find('s')
2
>>> myString.find('x')
-1

Example 2: python get first character of string

string = 'This is a string'
print(string[0])
#output: 'T'

Example 3: how to find the first letter of an item in python

mylist[0][0]   # get the first character from the first item in the list

Example 4: find first instance of character in string python

mystring.findfirstindex('dude') # should return 4

Tags:

Java Example