input()输入函数的构造和使用方法

在编程语言中有输出就有输入,下面我们就来看看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)

返回结果:
input()输入函数的构造和使用方法
文章图片

先打印的是python自学网,然后继续输入dd之后按回车键,又输出dd,是因为aa这个变量被重新赋值为dd。
下面在看一个案例:
bb = input('请输入你的年龄:') print(bb)

【input()输入函数的构造和使用方法】返回结果:
input()输入函数的构造和使用方法
文章图片

输入后回车的结果:input()输入函数的构造和使用方法
文章图片

文章来源:www.wakey.com.cn/document-input.html

    推荐阅读