add space before and after string python

using re adds white-space before and after the desired characters:

import re

pat = re.compile(r"([.()!])")
print (pat.sub(" \\1 ", string))
# hello .  .  .   ( world )  ! 

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
python insert space in string adding space in python using string function how to insert a space into a string python how to add a space in a string python python add a space after string add space after every character python python pint add space before and after string python adding space to string python add space between words in string add space before python how to add space in a string python python insert space into string how to add space after every character in a string python python how to add space to string python add string space add space in a string python python string add space how can i add a space in string in python python add space to string how to add extra space before words in python python insert before every space in string how to add space in python string add space after symbol python how to add space to string in python add space after all character python append string with space python python string insert space how to add space in string python insert space in string python python add space after each character how to add a space in the end of string in python adding space between string python how to add a space to a string in python how to append space in a string python saving string inserting extra spaces in python add space to python string python add space between strings add a space to a string python add space python string add space in string python add space after string print python adding space after every item python string adding space in string python how to insert a space in a string python add space between strings python insert a space into string python add a space after letter in python python insert space 4 characters in add space to string python how to add space while adding string in python python add space between words add space before and after string python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source