Skip to content
  • About
  • CoursesExpand
    • Problem Solving using C Language
    • Mastering Database Management
    • Linux System Administration
    • Linux and Shell Programming
  • Publications
  • Professional Certificates
  • BooksExpand
    • Books Authored
  • Patents
Download 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

Advance AI PPT

Read More Advance AI PPTContinue

Latest

Prompts for Image Descriptions

Describe the scene using three vivid sensory details — one for sight, one for sound, and one for touch. Summarize the mood of the image…

Read More Prompts for Image DescriptionsContinue

Latest

Dimensionality Reduction

Dimensionality reduction is the process of reducing the number of features (variables) in a dataset while preserving important information. It helps in: ✅ Reducing computational…

Read More Dimensionality ReductionContinue

Artificial Intelligence

Tanh Function in Neural Network

The tanh function, short for hyperbolic tangent function, is another commonly used activation function in neural networks. It maps any real-valued number into a value…

Read More Tanh Function in Neural NetworkContinue

Latest

Why Initialize Weights in Neural Network

Initializing weights and biases is a crucial step in building a neural network. Proper initialization helps ensure that the network converges to a good solution…

Read More Why Initialize Weights in Neural NetworkContinue

Nishant Munjal

Coding Humanity’s Future </>

Facebook Twitter Linkedin YouTube Github Email

Tools

  • SIP Calculator
  • Write with AI
  • SamplePHP
  • Image Converter

Resources

  • Blog
  • Contact
  • Refund and Returns

Legal

  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

© 2025 - All Rights Reserved

  • About
  • Courses
    • Problem Solving using C Language
    • Mastering Database Management
    • Linux System Administration
    • Linux and Shell Programming
  • Publications
  • Professional Certificates
  • Books
    • Books Authored
  • Patents
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.Ok