anonymous
  • 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.
Computer Science
chestercat
  • chestercat
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • 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 :-)
anonymous
  • 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
anonymous
  • anonymous
Great! Thanks, bmp.

Looking for something else?

Not the answer you are looking for? Search for more explanations.