Skip to content
  • About
  • Courses
  • ResearchExpand
    • Research Publications
    • Books
    • Patents
    • Ph.D. Supervised
  • Workshop/Conferences
  • ToolsExpand
    • Creative Image Converter
    • Creative QRCode Generator
    • Creative QR Code Generator Tool
    • EMI Calculator
    • SIP Calculator
  • Blog
  • Resume
One Page CV
Python

String Library

String Replace

str="Hello Bob"
print(str)
rstr=str.replace('Bob', 'James')
print(rstr)

This will replace the Bob with James and store it in the new variable. The variable ‘str’ will remain the same.

Strip or lstrip

str=" Hello Bob"
str.lstrip()

“Hello Bob” – spaces removed from the left

str="Hello Bob "
str.rstrip()

“Hello Bob” – spaces removed from the right

str=" Hello Bob "
str.strip()

“Hello Bob” – spaces removed from the left and right, also removes the ‘\n’ new line character from the end of the string.

Prefixes

line='Please take a sip of coffee'
line.startswith('Please')
True
line.startswith('P')
True
line.startswith('p')
False

Parsing and Extracting

Extracting data from an email ID required to search the letter ‘@’ then search the keyword ‘>’, then print the values between them. The below find function provides you the position of the

data= 'From Dr. Suyash Bhardwaj <suyash.bhardwaj@gkv.ac.in>'
at=data.find('@')
print(at)
41
great=data.find('>',at)
print(great)
31
domain=data[at+1:great]
print(domain)
gkv.ac.in

Post navigation

Previous Previous
‘in’ statement in String
NextContinue
String Data Type
  • Latest

    [professional_resume]

    Read More Continue

  • Latest

    Explore Generative AI with the Gemini API in Vertex AI

    Read More Explore Generative AI with the Gemini API in Vertex AIContinue

  • Latest

    Inspect Rich Documents with Gemini Multimodality and Multimodal RAG

    Read More Inspect Rich Documents with Gemini Multimodality and Multimodal RAGContinue

  • Latest

    🎓 Why Original Work Matters in Your Final Year Project (And How It Can Shape Your Career)

    In engineering colleges across the country, final year projects are often treated as just another academic task. But what many students fail to realize is…

    Read More 🎓 Why Original Work Matters in Your Final Year Project (And How It Can Shape Your Career)Continue

  • Latest

    🎓 How to Choose Your Final Year Project: A Practical Guide for BTech Students

    Choosing the right final year project is one of the most important decisions of your engineering journey. It’s more than just a submission — it’s…

    Read More 🎓 How to Choose Your Final Year Project: A Practical Guide for BTech StudentsContinue

Nishant Munjal

Coding Humanity’s Future </>


Facebook Twitter Linkedin YouTube Github Email

Tools

  • SIP Calculator
  • EMI Calculator
  • Creative QR Code
  • Image Converter

Resources

  • Blog
  • Contact
  • Refund and Returns

Legal

  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

© 2025 - All Rights Reserved

  • About
  • Courses
  • Research
    • Research Publications
    • Books
    • Patents
    • Ph.D. Supervised
  • Workshop/Conferences
  • Tools
    • Creative Image Converter
    • Creative QRCode Generator
    • Creative QR Code Generator Tool
    • EMI Calculator
    • SIP Calculator
  • Blog
  • Resume
Download CV
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.