简体   繁体   English

输入、sys.stdin 和函数

[英]Input, sys.stdin and functions

I created a function that takes 3 arguments: (n,m,H are integers)我创建了一个 function,它需要 3 个 arguments:(n,m,H 是整数)

def Day(n,m,H):
    ...

However, I have to use:但是,我必须使用:

for line in sys.stdin:
    print(line ,end = " ")

I tried a function that only requires one argument and did this, which worked.我尝试了一个只需要一个参数的 function 并且这样做了,它奏效了。

(x is an integer) (x 是一个整数)

def Square(x):
    y = x*x
    return y 

for line in sys.stdin:
    line = int(line)
    print(Square(line),end = " ")

I'm unsure as to how to do use it when there are 3 arguments.当有 3 个 arguments 时,我不确定如何使用它。 How would I do this?我该怎么做?

You could split the line you get from stdin :您可以splitstdin获得的行:

for line in sys.stdin:
    d = Day(*line.split())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM