1. 程式人生 > >4.28-python學習筆記(轉義符&input函數)

4.28-python學習筆記(轉義符&input函數)

轉義 換行 \n 出現 參考 python3 put 體重 否則

參考書目:《Learn Python The Hard Way》

##練習10
print("i am 6‘2\"tall.")#將雙引號轉義
print(i am 6\‘2"tall.)#將單引號轉義
#打印出來的就是引號裏的字符串,這個例子就是為了說明引號裏出現同種引號怎麽辦
tabby_cat="\ti‘m tabbled in."  #\t空格(橫向)
persian_cat="i‘m split\non a line"  #\n 新行
backslash_cat="i‘m \\a\\ cat"  #\\ 一個\
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) # 轉義字符 描述 # \(在行尾時) 續行符 # \\ 反斜杠符號 # \‘ 單引號 # \" 雙引號 # \a 響鈴 # \b 退格(Backspace) # \e 轉義 # \000 空
# \n 換行 # \v 縱向制表符 # \t 橫向制表符 # \r 回車 # \f 換頁 # \oyy 八進制數,yy代表的字符,例如:\o12代表換行 # \xyy 十六進制數,yy代表的字符,例如:\x0a代表換行 # \other 其它的字符以普通格式輸出 weather="ranning" print("\t*today is %s
"%weather) #格式化字符和轉義序列放在一起 ## 練習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)) #python3裏將沒有raw_input,只有input() #input()它希望能夠讀取一個合法的 python 表達式,即你輸入字符串的時候必須使用引號將它括起來,否則它會引發一個 SyntaxError #input()就是讓你輸入啦 #最後一個print把%s換成%r的話,年齡、體重、身高會加上引號 #把三個input()改成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 #跟練習11一個意思,但是更加簡練

4.28-python學習筆記(轉義符&input函數)