Remove whitespace in print function

Question:

I have this code

print "/*!",your_name.upper(),"*/";

where your_name is the data the user inputs.

How can I edit the code above to tell the system to remove any whitespace?

UPDATE:

If i print the code, i’ll get
/*! your_name */

I want to remove the whitspaces between /*! your_name */

Asked By: Michael

||

Answers:

The spaces are inserted by the print statement when you pass in multiple expressions separated by commas. Don’t use the commas, but build one string, so you pass in just the one expression:

print "/*!" + your_name.upper() + "*/"

or use string formatting with str.format():

print "/*!{0}*/".format(your_name.upper())

or the older string formatting operation:

print "/*!%s*/" % your_name.upper()

Or use the print() function, setting the separator to an empty string:

from __future__ import print_function

print("/*!", your_name.upper(), "*/", sep='')
Answered By: Martijn Pieters

The white spaces are inserted by print when you use multiple expressions separated by commas.

Instead of using commas, try :

print "/*!" + your_name.upper() + "*/"
Answered By: Alfie
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.