raw_input()与sys.stdin.readline()的区别

来源:互联网 发布:捕捞季节指标公式源码 编辑:程序博客网 时间:2024/06/05 01:03

readline函数用来读取来自键盘的一行文本输入,直到按回车为止

import systest1 = raw_input()print len(test1)test2 = sys.stdin.readline()print len(test2)</span>

C:\Users\Admin\Desktop>test.pyhello5hello6

由此可以看出,用readline时len所计算的长度还包含了换行符'/n'

可以利用strip()将其去掉

import systest1 = raw_input()print len(test1)test2 = sys.stdin.readline().strip()print len(test2)


C:\Users\Admin\Desktop>test.pyhello5hello5



0 0