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

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

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

Recent Tutorials:

  • BeautifulSoup Get Option Value
  • Creating an Image Cartoonizer with Flask - Complete with Source Code
  • How to use render_template in Flask
  • Convert Image to Text with Flask (Source Code)
  • Understand How to Work with Table in beautifulsoup
  • Estimating Reading Time of Text and Text File using Python
  • Beautifulsoup Get all Links
  • How to Use BeautifulSoup To Extract Title Tag

Related Tutorials:

  • 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
  • How To Solve no module named datasets
  • Python Get Root and Sub Domain From URL
  • Python-pycountry | Understand How to Use pycountry
  • Python: Get First, Second, Last word in String
  • Facebook
  • Twitter
  • Youtube

Copyright PyTutorial Blog Co.