logo
  • Python
  • Django
  • Tools
    • Email Extractor Tool Free Online
    • Calculate Text Read Time Online
    • HTML to Markdown Converter Online
    • Other Tools
  • About
  • Contact
  • Created with Sketch.
Created with Sketch.

Last modified: Jan 10, 2023 By Alexander Williams

Finding string in a text python [Simple Example]

to find string in text we'll use find() function

Table Of Contents

  • syntax
  • example

syntax

text.find(string)

example


#text    
text = "python is a great language"

index = text.find("great")

if index != -1:
    print('"great" is at index %s'% index)
    
else:
    print('"great" is not found')
        

output

#"great" is at index 12

Related Tutorials:

  • Understanding and Using Global Variables in Python
  • [Solved] ModuleNotFoundError: No module named 'numpy'
  • Removing Double Quotes from a String in Python: A Comprehensive Guide
  • How to Remove Words from a String in Python: Methods and Examples
  • Estimating Reading Time of Text and Text File using Python
  • 4 Ways to Find a Word in a List in Python: A Comprehensive Guide
  • How to read a string word by word in Python
  • 3 Easy Methods for Capitalizing Last Letter in String in Python

Recent Tutorials:

  • Fix Error: Cannot Find Module in Node.js
  • Fix Error: Cannot find module './app.js'
  • Fix Error: Cannot find module '../config'
  • Fix Error: Cannot find module '../../someFile'
  • Fix Error: Cannot find module './routes/index'
  • Fix Error: Cannot find module 'pg'
  • Fix Error: Cannot find module 'mysql2'
  • Fix Error: Cannot find module 'socket.io-client'
  • Facebook
  • Twitter
  • Youtube
  • PRIVACY POLICY
  • DMCA

Copyright 2025 PyTutorial Blog Co.

Privacy Preferences

We and our partners share information on your use of this website to help improve your experience. For more information, or to opt out click the Do Not Sell My Information button below.