Remove whitespace in print function in Python

Asked By 50 points N/A Posted on -
qa-featured

I have this code
print “/ *”, your_name.upper () “* /”;
your_name where the data entered by the user. How can I change the above code to tell the system, remove all spaces

UPDATE: When I print the code, I will
/ *! your_name * /

I want / remove spaces between Whit *! your_name * /

SHARE
Answered By 5 points N/A #188096

Remove whitespace in print function in Python

qa-featured

Happy to support you!

There are few steps that you can follow (but first convert the input data into a string if it is not),

  • You can use the str.replace() function, 
if the data input string is named as x,
x.replace(" ", "")
 
  • However, if you want to remove all white space characters including space, tab, new line, duplicate space, etc. you can use split then join:
x = ''.join(x.split())
 
  • Also you can use str.translate:
from x import whitespace
x.translate(None, whitespace)
or,
x.translate( None,x.whitespace )
 
 

Related Questions