10 python从键盘获取输入、刷新缓冲区

 1 ---python从键盘获取输入有两种方法:
 2 
 3 
 4 input与raw_input比较:
 5 
 6 #1.input函数:需要以合法的python表达式形式输入
 7 
 8 例1:
 9 >>> name = input ("what is your name ?")
10 what is your name ?
11 
12 当输入为数值型:3时,通过;当输入为字符型:lucy时,抱错:
13 
14 例2:
15 str = input("Enter your input: ");  
16 print "Received input is : ", str  
17 
18 ------------------------------------------
19 
20 #2.raw_input函数:
21 将会把所有的输入当原始数据处理,不会认为你的输入是一个表达式
22 
23 例:
24 str = raw_input("Enter your input : ");  
25 print "Received input is : ", str  
26 
27 
28 Enter your input: Hello Python  
29 Received input is :  Hello Python  
30 
31 -----------时实刷新缓冲区,打印内容---------------------------------
32 缓冲区的刷新方式:
33     1.flush()刷新缓存区
34     2.缓冲区满时,自动刷新
35     3.文件关闭或者是程序结束自动刷新。
36 
37 import sys
38 sys.stdout.flush()

猜你喜欢

转载自www.cnblogs.com/2mei/p/9254218.html
今日推荐