[Tutor] What's the difference between %s and %r?
amt
0101amt at gmail.com
Sat Jul 23 14:48:03 CEST 2011
Hello! I'm having troubles understanding what is the difference between %s
and %r(format characters). I did google and found something on
StackOverflow but I don't understand the explanation as it's not beginner
orientated.
Also, I have this code from learn python the hard way. Why at line 9 does he
uses %r? Why did he didn't wrote print "I said: %s." %x ?
1 x = "There are %d types of people." % 10
2 binary = "binary"
3 do_not = "don't"
4 y = "Those who know %s and those who %s." % (binary, do_not)
5
6 print x
7 print y
8
9 print "I said: %r." % x
10 print "I also said: '%s'." % y
11
12 hilarious = False
13 joke_evaluation = "Isn't that joke so funny?! %r"
14
15 print joke_evaluation % hilarious
16
17 w = "This is the left side of..."
18 e = "a string with a right side."
19
20 print w + e
Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110723/84c9412c/attachment.html>
More information about the Tutor
mailing list