“Python String Index ()” Kode Jawaban

indeks string python

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

Jawaban yang mirip dengan “Python String Index ()”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya