Answers for "how to get the string without space in python"

0

string without space pythonm

import re

string = '  Hello  World   From Pankaj \t\n\r\tHi There  '

print('Remove all spaces using RegEx:\n', re.sub(r"\s+", "", string), sep='')  # \s matches all white spaces
print()

print('Remove leading spaces using RegEx:\n', re.sub(r"^\s+", "", string), sep='')  # ^ matches start
print()

print('Remove trailing spaces using RegEx:\n', re.sub(r"\s+$", "", string), sep='')  # $ matches end
print()

print('Remove leading and trailing spaces using RegEx:\n', re.sub(r"^\s+|\s+$", "", string), sep='')  # | for OR condition
Posted by: Guest on August-24-2021
3

how to print values without space in python

x = 10
print ('The number of mangoes I have are "%d"' %x )
Posted by: Guest on November-19-2021

Code answers related to "how to get the string without space in python"

Python Answers by Framework

Browse Popular Code Answers by Language