Python学习入门基础教程(learning Python)--1.3 Python数据输入 .
2013-08-22 14:56
1116 查看
多数应用程序都有数据输入语句,用于读入数据,和用户进行交互,在Python语言里,可以通过raw_input函数实现数据的从键盘读入数据操作。
基本语法结构:raw_input(prompt)
通常prompt是输入提示符(字符串),raw_input一直读到回车键
为止。
内建函数input读入的是字符串数据。
eg1. 输入字符串
由于raw_input函数读入的键盘输入数据是字符串型的,如果本想传入整形,需调用类型转换函数int等函数进行相应的数据类型转换。
eg3. 读入浮点型数据
基本语法结构:raw_input(prompt)
通常prompt是输入提示符(字符串),raw_input一直读到回车键
为止。
内建函数input读入的是字符串数据。
eg1. 输入字符串
1 >>>name = raw_input("plz input your name:")2 >>>print(name)raw_input会将读入的输入赋值给等号左边的变量,程序执行结果如下。
>>> name = raw_input("plz input your name:")plz input your name:jeapedu.com>>> print(name)jeapedu.comeg2. 读入整形数据
由于raw_input函数读入的键盘输入数据是字符串型的,如果本想传入整形,需调用类型转换函数int等函数进行相应的数据类型转换。
1 >>> age = int(raw_input("plz input your age"))2plz input your age83 >>> print(age)4 8第1、3行为程序语句,第2、4行为输出结果。
eg3. 读入浮点型数据
1 >>> pay = float(raw_input("plz input your salary:"))2 plz input your salary:12.306 3 >>> print(format(pay, '.2f'))4 12.31第1、3行为程序语句,第2、4行为输出结果。
相关文章推荐
- Python学习入门基础教程(learning Python)--6 Python下的list数据类型
- Python学习入门基础教程(learning Python)--8.1 字典数据添加与删除
- Python学习入门基础教程(learning Python)--5.7 Python文件数据记录存储与处理
- Python学习入门基础教程(learning Python)--3.3.1 Python下的布尔表达式
- Python学习入门基础教程(learning Python)--2.3.1 Python传参函数设计
- Python学习入门基础教程(learning Python)--2 Python简单函数设计 .
- Python学习入门基础教程(learning Python)--1.2.1 Python输出语句print基本使用 .
- Python学习入门基础教程(learning Python)--2.1 Python下自定义函数 .
- Python学习入门基础教程(learning Python)--3.3.1 Python下的布尔表达式
- Python学习入门基础教程(learning Python)--2.3.3Python函数型参详解
- Python学习入门基础教程(learning Python)--3.3.1 Python下的布尔表达式
- Python学习入门基础教程(learning Python)--5.6 Python读文件操作高级
- Python学习入门基础教程(learning Python)--3.3.3 Python逻辑关系表达式
- Python学习入门基础教程(learning Python)--3.3.1 Python下的布尔表达式
- Python学习入门基础教程(learning Python)--2.2 Python下的变量基础 .
- Python学习入门基础教程(learning Python)--5.2 Python读文件基础
- Python学习入门基础教程(learning Python)--2.2.1 Python下的变量解析 .
- Python学习入门基础教程(learning Python)--2.3 Python自定义函数传参函数设计
- Python学习入门基础教程(learning Python)--3.3.2 Python的关系运算
- Python学习入门基础教程(learning Python)--2.3.1 Python传参函数设计