笨办法11提问-raw_input

源代码如下,有个改动

1 print "How old are you?",
2 age = raw_input()
3 print "How tall are you?",
4 height = raw_input()
5 print "How much do you weigh?",
6 weigh = raw_input()
7 
8 print "So, you're %r old, %s tall and %r heavy." % (age, height,weigh)

加分习题4:和转义序列有关的,想想为什么最后一行 ‘6’2”’ 里边有一个 ’ 序列。单引号需要被转义,从而防止它被识别为字符串的结尾。有没有注意到这一点?

print里的第二个%r改成%s就不会出现这个问题啦,输出结果如下: 
这里写图片描述


input和raw_input的区别,举个栗子:

1 print "raw_input numbers:",
2 A = raw_input()
3 print "input numbers:",
4 B = input()
5 
6 print "raw_input %r, input %r" % (A ,B) 

输出结果: 
这里写图片描述

input:会根据用户的输入来做类型的转换 
raw_input:则会把用户的输入都作为一个字符串来处理

原文地址:https://www.cnblogs.com/p36606jp/p/7648135.html