Solved

How can I print string without end of line character?

Posted on 2008-06-18
3
4,592 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

808 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