4.28-python学习笔记(转义符&input函数)

参考书目:《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一个意思,但是更加简练

猜你喜欢

转载自www.cnblogs.com/daxixixixi/p/8966650.html