Bibliography: Learn Python The Hard Way
# #Exercise 10 print ( " i am 6'2\"tall. " ) #Escape the double quotes print ( ' i am 6\'2"tall. ' ) #Escape the single quotes #What is printed is the quotes This example is to illustrate what to do if the same kind of quotation marks appear in quotation marks tabby_cat= " \ti'm tabbled in. " # \tSpace (horizontal) persian_cat= " i'm split\non a line " # \ n new line backslash_cat = " i'm \\a\\ cat " # \\ a \ fat_cat = ''' i'll do a list: \t* Cat food \t* Fishies \t* Cathlp\n\t* Grass ''' print (tabby_cat) print (persian_cat) print (backslash_cat) print (fat_cat) #escape character description # \(at end of line) line continuation character # \\ backslash symbol # \' single quote # \" Double quote # \a Bell # \b Backspace # \e Escape # \000 Empty # \n Linefeed # \v Vertical tab # \t Horizontal tab # \r Enter # \f Form feed # \oyy Octal number, the character represented by yy, for example: \o12 represents the newline # \xyy hexadecimal number, the character represented by yy, for example: \x0a represents the newline # \other Other The characters are output in normal format weather= " ranning " print ( " \t*today is %s " %weather) #Format characters and escape sequences together ## 练习11 print("How old are you?") age=input() print("How tall are you?") height=input() print("How much do you weigh?") weight = input() print ( " So,you're %s old,%s tall and %s heavy. " % (age,height,weight)) # There will be no raw_input in python3, only input() # input() It expects to be able to read a valid python expression, i.e. you must enclose it in quotes when you enter a string, otherwise it will raise a SyntaxError # input() is for you to enter # The last print replaces %s with If it is %r, the age, weight and height will be enclosed in quotation marks # Change the three input() to input("age:"), input("height:"), input("weight:") ##练习12 age=input("How old are you?") height=input("How tall are you?") weight =input( " How much do you weigh? " ) print ( " So,you're %s old,%s tall and %s heavy. " %(age,height,weight))22 #Same as exercise 11 , but more concise