一、知识介绍:

1、input() 函数,接收任意输入,将所有输入默认为字符串处理,并返回字符串类型;

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

2、可以用作文本输入,如用户名,密码框的值输入;

3、语法:input("提示信息:") 。

 

二、运用演示:

1、接收任意输入,并返回字符串类型;

>>>height = input("输入身高:")     #运行
输入身高: 170                      #输入整数170
>>> type(a)                       #type( )检查输出的数据类型
<class 'str'>                     #字符串

2、想得到一个整数,只需数据类型转换就可以了:

>>> a = int(input("身高:"))       #int( ) 转换为整数
身高: 180
>>> type(a)
<class 'int'>

 

三、案例分析:

Python3 | input() 函数 Python 第1张

Python3 | input() 函数 Python 第2张

 

(- * -)完(- * -)

,

1、input() 函数,接收任意输入,将所有输入默认为字符串处理,并返回字符串类型;

2、可以用作文本输入,如用户名,密码框的值输入;

3、语法:input("提示信息:") 。

 

二、运用演示:

1、接收任意输入,并返回字符串类型;

>>>height = input("输入身高:")     #运行
输入身高: 170                      #输入整数170
>>> type(a)                       #type( )检查输出的数据类型
<class 'str'>                     #字符串

2、想得到一个整数,只需数据类型转换就可以了:

>>> a = int(input("身高:"))       #int( ) 转换为整数
身高: 180
>>> type(a)
<class 'int'>

 

三、案例分析:

Python3 | input() 函数 Python 第3张

Python3 | input() 函数 Python 第4张

 

(- * -)完(- * -)

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄