天天看点

Python屏幕输入/输出 第三篇1      输出到屏幕 2      读取键盘输入

python输出到屏幕使用print命令。

运行命令:

print “Hello,world”

屏幕输出结果:

Hello,world

Python提供了两个内置函数从标准输入读入一行文本,默认的标准输入是键盘。如下:

两个输入函数分别是raw_input和input,他们的主要区别是:

1、  input函数支持输入表达式计算,而raw_input函数会把计算表达式作为字符串

2、  input函数输入字符串时需要在字符串两边加上单引号或者双引号,而raw_input函数则不需要。

input在输入数字时可以直接输入数字即可,但是如果输入字符串时则需要在字符串两边打上单引号或者双引号,否则会报错。

代码:

while 1:

     com=input()

     if com=='out':

         break

     else:

         print com

运行结果:

<a href="http://s2.51cto.com/wyfs02/M02/8C/1A/wKiom1hiAdzRSqaiAAAO2-kX53g580.png" target="_blank"></a>

raw_input函数把所有的输入全部作为字符串处理,所以在输入的时候是不需要加单引号或者双引号的。

程序代码:

     com=raw_input()

        break

        print com

        print type(com)         //type函数式显示字符串的类型的

程序执行结果:

<a href="http://s2.51cto.com/wyfs02/M02/8C/16/wKioL1hiAd3jbkkeAAAE1z3WRvw669.png" target="_blank"></a>

本文转自 老鹰a  51CTO博客,原文链接:http://blog.51cto.com/laoyinga/1886499