Print variable in python without space or newline
Question:
print a variable without newline or space
python3 does it by print (x,end=”)
how to do it in python 2.5
Answers:
Easy:
print x,
Note comma at the end.
sys.stdout.write
writes (only) strings without newlines unless specified.
>>> x = 4
>>> print x
4
>>> import sys
>>> sys.stdout.write(str(x)) # you have to str() your variables
4>>> # <- no newline
print a variable without newline or space
python3 does it by print (x,end=”)
how to do it in python 2.5
Easy:
print x,
Note comma at the end.
sys.stdout.write
writes (only) strings without newlines unless specified.
>>> x = 4
>>> print x
4
>>> import sys
>>> sys.stdout.write(str(x)) # you have to str() your variables
4>>> # <- no newline