🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

python print

Started by
9 comments, last by nano 21 years ago
quote: Original post by nano
I got errors that were telling me that thoe characters were invalid, but I guess someinth else caused it. The percent character is however causing problems, so I have to change
all % as %%.

You do know what the % is for, right? It works somewhat like the C printf:

print "Hello %s" % "world"

If you need multiple parameters, you need to use a sequence:

print "Hello %s from %s" % ( "world", "norway" )

The syntax I used above is an extension of that, allowing you to use named parameters in conjunction with a dictionary:

print "Hello %(to)s from %(from)s" % { "to" : "world", "from" : "Norway" }

It is very useful when you use it with the locals() function, which returns a dictionary of all local variables.

quote:
Wow, I thought the triple-quoted strings were only useful as docstrings. I never saw anything like this in the documentation.

I think Guido''s tutorial covers it.


AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement