关于python:input输入函数的构造和使用方法

6次阅读

共计 621 个字符,预计需要花费 2 分钟才能阅读完成。

在编程语言中有输入就有输出,上面咱们就来看看 input()输出函数,还是老规矩先看看输出函数的结构。

def input(*args, **kwargs): # real signature unknown
    """
    Read a string from standard input.  The trailing newline is stripped.
    
    The prompt string, if given, is printed to standard output without a
    trailing newline before reading input.
    
    If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
    On *nix systems, readline is used if available.
    """
    pass

从构造函数咱们能够看到 input 传入的参数是 arg, *kwargs,这两个参数示意能够在函数内传入任何模式的变量或其余数据类型。
上面咱们就来演示一下:

c = 'python 自学网'
aa = input(c)print(aa)

返回后果:

先打印的是 python 自学网,而后持续输出 dd 之后按回车键,又输入 dd,是因为 aa 这个变量被从新赋值为 dd。
上面在看一个案例:

bb = input('请输出你的年龄:')
print(bb)

返回后果:

输出后回车的后果:
文章起源:www.wakey.com.cn/document-input.html

正文完
 0