W3Schools.com (2024)

❮ String Methods

Example

Where in the text is the word "welcome"?:

txt = "Hello, welcome to my world."

x = txt.index("welcome")

print(x)

Try it Yourself »

Definition and Usage

The index() method finds the first occurrence of the specified value.

The index() method raises an exception if the value is not found.

The index() method is almost the same as thefind() method, the only difference is that the find() method returns -1 if the value is not found. (See example below)

Syntax

string.index(value, start, end)

Parameter Values

Parameter Description
value Required. The value to search for
start Optional. Where to start the search. Default is 0
end Optional. Where to end the search. Default is to the end of the string

More Examples

Example

Where in the text is the first occurrence of the letter "e"?:

txt = "Hello, welcome to my world."

x = txt.index("e")

print(x)

Try it Yourself »

Example

Where in the text is the first occurrence of the letter "e" when you only search between position 5 and 10?:

txt = "Hello, welcome to my world."

x = txt.index("e", 5, 10)

print(x)

Try it Yourself »

Example

If the value is not found, the find() method returns -1, but the index() method will raise an exception:

txt = "Hello, welcome to my world."

print(txt.find("q"))
print(txt.index("q"))

Try it Yourself »

❮ String Methods

W3schools Pathfinder

Track your progress - it's free!

W3Schools.com (2024)
Top Articles
How to mine Ethereum Classic?
Bank of America, Wells Fargo to Offer Spot Bitcoin ETFs to Clients: Bloomberg
Jack Doherty Lpsg
Ohio Houses With Land for Sale - 1,591 Properties
Dragon Age Inquisition War Table Operations and Missions Guide
Academic Integrity
Miss Carramello
Best Cheap Action Camera
Cosentyx® 75 mg Injektionslösung in einer Fertigspritze - PatientenInfo-Service
Buckaroo Blog
Youtube Combe
Large storage units
fltimes.com | Finger Lakes Times
Our Facility
More Apt To Complain Crossword
About Us | TQL Careers
Money blog: Domino's withdraws popular dips; 'we got our dream £30k kitchen for £1,000'
Munich residents spend the most online for food
Po Box 35691 Canton Oh
Roll Out Gutter Extensions Lowe's
Accident On May River Road Today
Moving Sales Craigslist
Lowes Undermount Kitchen Sinks
Tyler Sis University City
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Georgia Cash 3 Midday-Lottery Results & Winning Numbers
Sussyclassroom
Egizi Funeral Home Turnersville Nj
Talkstreamlive
Why Are Fuel Leaks A Problem Aceable
Hefkervelt Blog
Jurassic World Exhibition Discount Code
Bayard Martensen
Lcsc Skyward
WOODSTOCK CELEBRATES 50 YEARS WITH COMPREHENSIVE 38-CD DELUXE BOXED SET | Rhino
Restaurants Near Calvary Cemetery
Rust Belt Revival Auctions
Petsmart Distribution Center Jobs
Green Bay Crime Reports Police Fire And Rescue
Helloid Worthington Login
Flashscore.com Live Football Scores Livescore
Albertville Memorial Funeral Home Obituaries
Gvod 6014
Second Chance Apartments, 2nd Chance Apartments Locators for Bad Credit
Despacito Justin Bieber Lyrics
Child care centers take steps to avoid COVID-19 shutdowns; some require masks for kids
Human Resources / Payroll Information
Maplestar Kemono
25 Hotels TRULY CLOSEST to Woollett Aquatics Center, Irvine, CA
Page 5747 – Christianity Today
Tweedehands camper te koop - camper occasion kopen
Access One Ummc
Latest Posts
Article information

Author: Greg O'Connell

Last Updated:

Views: 5429

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Greg O'Connell

Birthday: 1992-01-10

Address: Suite 517 2436 Jefferey Pass, Shanitaside, UT 27519

Phone: +2614651609714

Job: Education Developer

Hobby: Cooking, Gambling, Pottery, Shooting, Baseball, Singing, Snowboarding

Introduction: My name is Greg O'Connell, I am a delightful, colorful, talented, kind, lively, modern, tender person who loves writing and wants to share my knowledge and understanding with you.