Created
August 4, 2011 10:59
-
-
Save adaptives/1124963 to your computer and use it in GitHub Desktop.
Exercise 6 (with comments)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #assign a String to the variable x. The String is a formatted String | |
| #where we replace %d with 10 | |
| x = "There are %d types of people." % 10 | |
| #assign the variable 'binary' with a value which is a String 'binary' | |
| binary = "binary" | |
| #assign a String to the variable do_not | |
| do_not = "don't" | |
| #assign a String to the variable y. This is a formatted String which has | |
| #two replecement variables | |
| #This is the first place where a String is put inside a String | |
| y = "Those who know %s and those who %s." % (binary, do_not) | |
| #print the value of the variable x | |
| print x | |
| #print the value of the variable y | |
| print y | |
| #print the specified String which also contains a replacement | |
| #In this case we use the %r formatting character, which will | |
| #be replaced witht the String representation of the specified object | |
| #This is the second place where a String is put inside a String | |
| print "I said: %r" % x | |
| #print the specified String, which contains a replacement value | |
| #This is the third place where a String is put inside a String | |
| print "I also said: '%s'." % y | |
| #set the variable 'hilarious' to the boolean value False | |
| hilarious = False | |
| #Set the variable 'joke_evaluation' to the String containing a replacement | |
| #value. We do not specify the replacement here. It will be specified | |
| #when we use the String | |
| joke_evaluation = "Isn't that joke so funny?! %r" | |
| #print the value of the String 'joke_evaluation' and use the value of | |
| #the String 'hilarious' as a replacement | |
| #This is the fourth place where a String is put inside a String | |
| print joke_evaluation % hilarious | |
| #assign a String value to the variable 'w' | |
| w = "This is the left side of..." | |
| #assign a String value to the variable 'e' | |
| e = "a string with a right side." | |
| #concatanate w and e and print the result | |
| print w + e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment