首页 > 其他分享 >关于input( )和sys.stdin.readline( )的区别

关于input( )和sys.stdin.readline( )的区别

时间:2023-06-07 14:11:29浏览次数:32  
标签:int stdin sys strip print input readline

sys.stdin.readline( )会将标准输入全部获取,包括末尾的'\n',
input()会把‘\n’忽略


sys.stdin.readline( ).strip()  去掉末尾的换行符,

 

import sys
a=sys.stdin.readline().strip()
b=input()
print(a, type(a))
print(b, type(b))

#  678 <class 'str'>
#  678 <class 'str'>



for line in sys.stdin:
    a, b = map(int, line.strip().split())
    print(a + b)


for line in sys.stdin:
    a, b = map(int, line.strip().split())
    print(a + b)

try:
    while 1:
        print('输入一个数: ')
        n = int(sys.stdin.readline().strip('\n'))
        print('输入多个数,空格分开:(什么都不输退出) ')  # 若是多输入,strip()默认是以空格分割,返回一个包含多个字符串的list
        sn = sys.stdin.readline().strip()
        if sn == '':
            break
        sn = list(map(int,sn.split()))  # 将列表元素转化成int类型
        print('一个数:', n)
        print('多个数:', sn)
except Exception as e:
    print("出错咧:", e)

  

标签:int,stdin,sys,strip,print,input,readline
From: https://www.cnblogs.com/sangern/p/17463133.html

相关文章

  • input框记住密码之后样式取消
    input:-webkit-autofill{-webkit-text-fill-color:#fff!important;/*记住密码的字的颜色*/transition:background-color5000sease-in-out0s;/*延时渲染背景色来去除背景色*/caret-color:#fff;/*光标颜色*/}input:focus{/*外边框线去除*/outline:none;......
  • IO流 p9 转换流-InputStreamReader 和 OutputStreamWriter
    转换流-InputStreamReader和OutputStreamWriter介绍InputStreamReader:Reader的子类,可以将InputStream(字节流)包装成Reader(字符流);OutputStreamWriter:Writer的子类,实现将OutputStream(字节流)包装成Writer(字符流);当处理纯文本数据时,如果使用字符流效率更高,并且可以有效解决中文......
  • 合并数组与非合并数组 -- SystemVerilog
    合并型数组(packed):合并型数组可以实现连续的存储,赋值时不需要用 ’{}。 数组中,数据排列为{ b_pack[2], b_pack[1],b_pack[0]},其中每个b_pack为8个bit;bit是二值逻辑,每位bit只占据1位。故24位(8bit*3)只占据一个word(一般一个word为32bit)的存储空间。 非合并型数组......
  • KingbaseES V8R6集群运维系列 -- 修改ssh通信为 sys_securecmdd 通信
    一、适用于:本文档使用于KingbaseESV008R006版本。二、关于SYS_SECURECMDD:sys_securecmdd是KingbaseES集群自带的工具,集群监控、管理集群时通过sys_securecmdd安全执行命令而不使用ssh服务。sys_securecmdd主要包含以下文件:服务端sys_securecmdd默认监听8890端口,接受客......
  • KingbaseES sys_bulkload数据加载工具错误处理
    一、关于sys_bulkload数据加载工具sys_bulkload是KingbaseES提供的快速加载数据的命令行工具。用户使用sys_bulkload工具能够把一定格式的文本数据简单、快速的加载到KingbaseES数据库中,或将KingbaseES数据库中的数据快速导出到CSV文件中。使用前需要用户手动创建sys_bulkload插......
  • BootStrap_实现导入Excel(BootStrap-InputFile)【实例】
    BootStrap_实现导入Excel(BootStrap-InputFile)【实例】weixin_40877388于2020-03-3114:52:47发布分类专栏:BootStrap版权订阅专栏一、前言在批量加入学生信息的时候,我们通常采用Excel导入的方式,方便,快捷。本篇使用SpringBoot+BootStrap-InputFile+poi的结合方式,写......
  • SystemVerilog for Design Edition 2 Chapter 7
    SystemVerilogforDesignEdition2Chapter7SystemVerilogaddsseveralnewoperatorsandproceduralstatementstotheVeriloglanguagethatallowmodelingmoreconcisesynthesizableRTLcode.Additionalenhancementsconveythedesigner’sintent,helping......
  • 极客大挑战2019EasySQL
     如果不输入 随便输入 由地址栏的check.php?username=sadsad&password=sadsad可以猜测sql语句:$sql="select*fromxxwhereusername='$name'andpassword='$password'";既然是考sql注入,先试试万能密码用户名:’or1#密码随意判断是否正确的sql语句可能为:$sql="sel......
  • p6 BufferedInputStream 和 BufferedOutputStream
    BufferedInputStream和BufferedOutputStreamBufferedInputStreamBufferedInputStream是字节流,在创建BufferedInputStream时,会创建一个内部缓冲区数组。构造方法摘要ConstructorandDescriptionBufferedInputStream(InputStreamin)创建一个BufferedInputStr......
  • .NET使用System.Speech轻松读取文本
    System.Speech是.NET框架的一部分,提供了语音识别和语音合成的功能。通过使用System.Speech命名空间中的类,开发人员可以在.NET应用程序中实现语音识别功能。在本文中,我将演示如何使用System.Speech.NET,这是开发语音应用程序比较牛逼的内库。它适用于.NET4.x和.NETCore以上版本......