熟悉输入
1、在 Python2.x 中 raw_input( ) 和 input( ),两个函数都存在,其中区别为:
- raw_input( ) 将所有输入作为字符串看待,返回字符串类型。
- input( ) 只能接收"数字"的输入,在对待纯数字输入时具有自己的特性,它返回所输入的数字的类型( int, float )。
2、在 Python3.x 中 raw_input( ) 和 input( ) 进行了整合,去除了 raw_input( ),仅保留了 input( ) 函数,其接收任意任性输入,将所有输入默认为字符串处理,并返回字符串类型。
来自 <https://www.runoob.com/w3cnote/python2-python3-raw_input-and-input.html>
练习
#python3 用input()输入 , end = ""控制不换行
print ("How old are you?", end = " ")
age = input()
print ("How tall are you?", end = " "),
height = input()
print ("How much do you weigh?", end = " "),
weight = input()
print ("So, you're %r old, %r tall and %r heavy."% ( age, height, weight))
打印结果