Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 10th, 2007, 1:23 PM   #11
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Talking

I looked at the link, that note is simply a mistake in that case. It is correct if you line up a bunch of variables with commas directly after a print.

Another solution for the OP:
def square(x):
    return x * x

print "Value   Square"

for i in range(1, 6):
    print str(i) + "   " + str(square(i))
Now you have all strings and concatination works fine.

This would add a space for each comma used:
def square(x):
    return x * x

print "Value   Square"

for i in range(1, 6):
    print i, "   ", square(i)
__________________
I looked it up on the Intergnats!

Last edited by Dietrich; Jul 10th, 2007 at 1:38 PM.
Dietrich is offline   Reply With Quote
Old Jul 11th, 2007, 2:11 AM   #12
ZenMasterJG
Hobbyist Programmer
 
ZenMasterJG's Avatar
 
Join Date: Nov 2004
Location: Boston, MA
Posts: 147
Rep Power: 4 ZenMasterJG is on a distinguished road
Send a message via AIM to ZenMasterJG
i like:
print "Value\tSquare"
for pair in [ (x, x*x for x in xrange(1, 6) ]:
     print "%d\t%d"%(pair[0], [pair[1])
ZenMasterJG is offline   Reply With Quote
Old Jul 18th, 2007, 8:52 AM   #13
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Talking

Quote:
Originally Posted by ZenMasterJG View Post
i like:
print "Value\tSquare"
for pair in [ (x, x*x for x in xrange(1, 6) ]:
     print "%d\t%d"%(pair[0], [pair[1])
I figured you would that kind of complex person!
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginers Python Tutorial Beegie_B Python 15 Jul 28th, 2006 11:43 AM
[tutorial] Python for programming beginners coldDeath Python 30 Dec 14th, 2005 11:35 AM
Convert Python script to C++ code clanotheduck Python 17 Sep 25th, 2005 8:55 AM
Advanced Python Tricks Arevos Python 19 Sep 24th, 2005 7:39 AM
Python - A Programmers Introduction coldDeath Python 17 Aug 19th, 2005 12:41 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:51 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC