Solved

How can I print string without end of line character?

Posted on 2008-06-18
3
4,618 Views
Last Modified: 2012-06-27
I'm trying to write a script that print first 50 numbers separated by , without any spaces, end of line characters between number. How can I do that?
I tried to use:
print ",",
however it generates extra space between words
#!/usr/bin/python
 
for i in range(1,51):
	if i > 1:
		print ","
	print "%d" % i

Open in new window

0
Comment
Question by:pmnox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 250 total points
ID: 21816542
Try:
#!/usr/bin/python
 
import sys
for i in range(1,51):
     if i>1:
             sys.stdout.write(',')
     print i,

Open in new window

0
 
LVL 17

Expert Comment

by:ramrom
ID: 21816578

#!/usr/bin/python
 
print ",".join(str(i) for i in range(50))

Open in new window

0
 

Author Closing Comment

by:pmnox
ID: 31468524
thx. I didn't know that I can use sys.stdout.write function instread of print
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question