Home How to print without newline or space?
Reply: 0

How to print without newline or space?

user6138
1#
user6138 Published in September 19, 2018, 6:43 pm

The question is in the title.

I'd like to do it in python. What I'd like to do in this example in c:

#include <stdio.h>

int main() {
    int i;
    for (i=0; i<10; i++) printf(".");
    return 0;
}

Output:

..........

In Python:

>>> for i in xrange(0,10): print '.'
.
.
.
.
.
.
.
.
.
.
>>> for i in xrange(0,10): print '.',
. . . . . . . . . .

In Python print will add a \n or a space, how can I avoid that? Now, it's just an example. Don't tell me I can first build a string then print it. I'd like to know how to "append" strings to stdout.

share|improve this question
  • 5
    For those who search the string formating documentation of python: docs.python.org/library/stdtypes.html#string-formatting – guettli Sep 16 '11 at 9:16

25 Answers 25

active oldest votes
up vote 1948 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.49191 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO