Here is another little trick in Python; the print statement always inserts a line break after it prints your text, for example:
print "Hello" print "Python" print "!"
Will print:
Hello
Python
!
Now, you can fix the issue with the line break by inserting a comma after the print statement:
print "Hello", print "Python", print "!"
This will print:
Hello Python !
But the problem is that it will still insert a space after it prints the text, so to fix this you will have to use sys.stdout.write like this:
import sys sys.stdout.write("Hello ") sys.stdout.write("Python") sys.stdout.write("!")
This will print:
Hello Python!
Have fun with Python
Hamid Alipour is a partner in Codehead, LLP with his wife, Tess. Hamid speaks 12 markup and programming languages [Yes, 12: PHP, CSS, Ajax, JavaScript, HTML/XHTML, Java, Python, C/C++, ASP, Visual Basic, Scheme and Action Script]; has a penchant for solving the unsolvable; an affinity for clean, hand-written code and is a Zend Certified 
For Python 3.0 the print statement is now a function.
print “Hello!” is now print(“Hello!”)
Your space-less example would be obtained by using the sep paramater.
print(“Hello “, “Python”, “!”, sep=”")
Comment — November 6, 2008 @ 3:58 pm
Jake, that’s good to know, thanks!
I didn’t have time to look at Python 3.0 yet.
Comment — November 6, 2008 @ 4:11 pm
in Python 5, the print statement can be used as a statement, or a function. It doesnt matter.
Comment — December 16, 2008 @ 7:24 pm
Python 5?!
Comment — December 16, 2008 @ 7:41 pm
Thanks, This was very clear and concise. I’m glad that people like you take the time to post stuff like this so people like me don’t have to take the time to crack a book!
Comment — June 11, 2009 @ 10:39 am
LOL python 5? typo? 3 is the latest public version
Comment — September 4, 2009 @ 3:16 pm
No, he is right, python 5 supports print as a statement or a function. I think its rather useless that they would restrict you in python 3
Comment — September 6, 2009 @ 11:58 am
I have a little doubt here…
this post here solved 50% of my problem…
disclaimer : i am a beginner
In C/c++ you have functions to respond to keyboard interupt…like getch()…hence,the moment you tap on a key..it returns a value or gives control main()..
What is the equivalent method in python to read keyboard interrupts?
Also,this does not really solve it yet,
I need to print a ‘[' and then read a string and then immediately print another ']‘ without any spaces.
But the way python appears to work , until and unless i hit enter , it does not move to the next line of code.Hence no matter what i do i get the ‘]’ on the next line.
Please help me out here , i seem to be missing out on something.
the piece of code:
Comment — October 28, 2009 @ 5:47 am
For unbuffered read, see this thread.
http://code.activestate.com/recipes/134892/
Comment — November 4, 2009 @ 2:35 pm