如何指定输入?
输入吗
input("Enter a word and a number: ")
?
Enter a word and a number: hello 14
有人知道如何执行这样的
有人知道这样做的“作弊”吗?
Does someone know how to do an input like that:
input("Enter a word and a number: ")
and in the console we write:
Enter a word and a number: hello 14
It reconize it like [word] [number]
.
Does someone know a "cheat" to do something like that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
input()
是一个超简单的功能,它将用户输入将用户输入作为字符串吐出到变量中。如果您知道输入的格式,则可以使用正则表达式(如果您熟悉C的scanf()
,则可以觉得这很有用:)在这种情况下,因此:
请参阅: https:// https:// https:// docs.python.org/3/library/re.html#match-objects
input()
is a super simple function that will just spit out the user input as a string into a variable. If you know the format the input should be in though, you can parse it using regular expressions (if you're familiar with C'sscanf()
you may find this useful: https://docs.python.org/3/library/re.html#simulating-scanf)In this case, as such:
See: https://docs.python.org/3/library/re.html#match-objects
inp [0]
将是单词和int(inp [1])
将是数字。重要的是要注意,带有空参数的.split()将自动解释为.split('')
inp[0]
will be the word andint(inp[1])
will be the number.It is important to note that .split() with an empty argument will automatically be interpreted as .split(' ')