fosshelp
Sunday, April 17, 2011
python Named string formatting example
python Named string formatting example
my_dict = {'foo': 'answer', 'bar':42}
print "The %(foo)s is %(bar)i." % my_dict
#New Style Formatting
print("The {foo} is {bar}".format(foo='answer', bar=42))
OUTPUT
=======
The answer is 42.
The answer is 42
No comments:
Post a Comment
‹
›
Home
View web version
No comments:
Post a Comment