Site Loader
111 Rock Street, San Francisco


Text içinde geçen bir string‘in index numarası bulmak.

work_tip = "A snippet is a small chunk of PHP code that you can use to extend the " \
           "functionality of a WordPress-powered website; essentially a mini-plugin with " \
           "less load on your site. Most snippet-hosting sites tell you to add snippet code " \
           "to your active theme's functions.php file, which can get rather long and messy after a while."
code_index =work_tip.find("code")
while code_index > 0:
    print("'snippet' is at index",code_index)
    code_index = work_tip.find("snippet",code_index+1)
    if code_index == -1:
        print("no more 'snippet'")

work_tip text’i içinde geçen ‘snippet’ string’inin index numaralarını gösterir. Çıktısı aşağıdaki gibidir.

‘snippet’ is at index 34
‘snippet’ is at index 176
‘snippet’ is at index 214
no more ‘snippet’

Post Author:

Leave a Reply

Your email address will not be published. Required fields are marked *