“Python String Index ()” Code-Antworten

Python String Index von

sentence = 'Python programming is fun.'

result = sentence.index('is fun')
print("Substring 'is fun':", result)

result = sentence.index('Java')
print("Substring 'Java':", result)
Healthy Heron

Python String Index ()

myStr = "py py py py"
print(myStr.find("js"))
print(myStr.index("js"))
codelearner

Python String Index ()

myStr = "py py py py"
print(myStr.find("js"))
print(myStr.index("js"))


## OUTPUT:

-1
Traceback (most recent call last):
  File "D:\Programming\python\article\find.py", line 38, in <module>
    print(myStr.index("js"))
ValueError: substring not found
codelearner

Python String Index ()

myStr = "py py py py"
print(myStr.find("js"))
print(myStr.index("js"))
codelearner

Python String Index ()

myStr = "py py py py"
print(myStr.find("js"))
print(myStr.index("js"))
codelearner

Ähnliche Antworten wie “Python String Index ()”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen