[Courses] [python] Lesson 1: Hello world

Akkana Peck akkana at shallowsky.com
Tue Jun 21 04:02:06 UTC 2011


Eric Slehofer writes:
> I had a quick question that came to me while experimenting a bit with the
> print statement. Normally print gives you one space between the arguments of
> the print statement and we've covered how to have no spaces between its
> arguments. Now is there a way for you to (for whatever reason) have more
> than one space between the arguments of the print statement (other than, for
> example, placing spaces in the string itself i.e. print "Hello,       ",
> name)?

Of course there's a way. There's a way to do pretty much everything
in Python. :-)  But it's quite a bit more advanced. You could use
join, which would look something like this:
print '    '.join(["hello", name])

I'm not going to explain that now, though -- that would require
skipping ahead at least three lessons. :-)

> Also, is there a way to still use single quotes and avoid the problems with
> apostrophes in the string? Some sort of escape character, perhaps (like a
> backslash in bash)?

Yes, backslashes work in Python strings too.

	...Akkana


More information about the Courses mailing list