初识python - 输入和输出
Posted jhui104
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了初识python - 输入和输出相关的知识,希望对你有一定的参考价值。
若你的程序要接收用户指令,可以用input语法:
name = input("What is your name?") print("Hello " + name )
执行脚本就会发现,程序会等待你输入姓名后再往下继续走。
可以让用户输入多个信息,如下
name = input("What is your name?") age = input("How old are you?") hometown = input("Where is your hometown?") print("Hello ",name , "your are ", age , "years old, you came from",hometown)
结果输出
What is your name?Pang Hu How old are you?22 Where is your hometown?BeiJing Hello Pang Hu your are 22 years old, you came from BeiJing
注意,input()方法接收的只是字符串,即使你输入的是数字,它也会按字符串处理
以上是关于初识python - 输入和输出的主要内容,如果未能解决你的问题,请参考以下文章