Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

I've been using this older c-style substitution in Python: "Hello, %s!" % name Apparently there is a newer way of substituting variables. Can someone fill me in on this? Thanks.

OpenStudy (anonymous):

The other way to format that I know of is to create a dictionary, i.e.: print 'This %(name)s is wrong by %(#)d' % {'name' : 'sentence', '#': 4}. I do think that Python 3.x has another way to format, but I don't really remember it. I will look into it :-)

OpenStudy (anonymous):

Ah, found it. According to the BDFL's Introduction to Python, one should use str.format because of deprecation. Check this example: http://codepad.org/GSOQwMB8

OpenStudy (anonymous):

Great! Thanks, bmp.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!