Profile

Click to view full profile
Hi, I'm Veerapat Sriarunrungrueang, an expert in technology field, especially full stack web development and performance testing.This is my coding diary. I usually develop and keep code snippets or some tricks, and update to this diary when I have time. Nowadays, I've been giving counsel to many well-known firms in Thailand.
view more...

Monday, October 25, 2010

Print without a new line or space in Python

Normally, when we use print function in Python, it will automatically put new line at the end of the string. we can't omit it. So, there are 2 solutions as following:

1.
import sys 
sys.stdout.write("Hello")

2.
from __future__ import print_function 
print("Hello",end="")

Normally, end="\n" and print is not a function that means after string it will  be add "\n" at the end. Using __future__ to import print as function.

Now, we can print without a new line.

No comments:

Post a Comment