473,511 Members | 15,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How avoid both a newline and a space between 2 print commands?

print "foo"
print "bar"

has a newline in between "foo" and "bar"

print "foo",
print "bar"

has a space in between "foo" and "bar"

How prevent ANYTHING from going in between "foo" and "bar" ??

(Without defining a string variable.)

Chris
Jan 23 '08 #1
4 1535
se******@spawar.navy.mil wrote:
print "foo"
print "bar"

has a newline in between "foo" and "bar"

print "foo",
print "bar"

has a space in between "foo" and "bar"

How prevent ANYTHING from going in between "foo" and "bar" ??

(Without defining a string variable.)
sys.stdout.write("foo")
sys.stdout.write("bar")

Diez
Jan 23 '08 #2
On Jan 23, 9:03 am, "seber...@spawar.navy.mil"
<seber...@spawar.navy.milwrote:
print "foo"
print "bar"

has a newline in between "foo" and "bar"

print "foo",
print "bar"

has a space in between "foo" and "bar"

How prevent ANYTHING from going in between "foo" and "bar" ??

(Without defining a string variable.)

Chris
print "%s%s" % ("foo", "bar") ## If "%s%s" doesn't violate your
condition of not defining a string variable, I'm not sure.
Jan 23 '08 #3
On Jan 23, 6:12 am, "Diez B. Roggisch" <de...@nospam.web.dewrote:
sys.stdout.write("foo")
sys.stdout.write("bar")
Diez

Thanks. Beautiful! I <3 Python!

Chris
Jan 23 '08 #4
"se******@spawar.navy.mil" <se******@spawar.navy.milwrites:
On Jan 23, 6:12 am, "Diez B. Roggisch" <de...@nospam.web.dewrote:
sys.stdout.write("foo")
sys.stdout.write("bar")

Diez

Thanks. Beautiful! I <3 Python!
Even better, this form will survive unchanged into Python 3, whereas
the 'print' statement will undergo some changes in syntax and
perhaps semantics.

--
\ "Free thought is a necessary, but not a sufficient, condition |
`\ for democracy." —Carl Sagan |
_o__) |
Ben Finney
Jan 23 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3733
by: Gregory | last post by:
I am working through the exercises in the book "Learning PHP 5". I am using OS 10.3.7, with Apache, Safari and IE. When I execute the following code, the newline "\n" does not work. The ouput is...
5
7782
by: Tobiah | last post by:
This is a stumbling block for me. Is there a better way to output *just* what I want? I want the output "foobar" >>> print "foo"; print "bar" foo bar >>> print "foo",; print "bar"
4
7199
by: fowlertrainer | last post by:
Hi ! I want to print, but without newline. I want to create a progress for ftp, but the print is drop a newline for every percent. I want like this: 0% 25% 50% 75% 100% But this happening:...
4
2214
by: Alex Hunsley | last post by:
Very very simple problem here, can't find out how to do it... I want to print something without a new line after it, so I can later output something right after it on the same line. If I do: ...
9
22147
by: Paul Watson | last post by:
I thought that using a comma at the end of a print statement would suppress printing of a newline. Am I misunderstanding this feature? How can I use print and not have a newline appended at the...
6
6734
by: 3strands | last post by:
Hi! I am writing a C++ program for a school project. It's a project and I could do it without this particualr feature, it's just it would be better if I could find out one thing: I'm making...
8
2485
by: Samuel | last post by:
Hello, I have been searching for an answer for almost two hours now and have not found an answer. I want this code: for i in range(3): print i # or whatever To produce this output: 012
11
14978
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
9
3084
by: DataSmash | last post by:
I simply want to capture the free disc space in a variable so that I can compare changes. I'm aware of a few commands like "df -h" or "du - k", but I can't figure out how to capture those values...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.