Python读取键盘输入的2种方法
作者:junjie 时间:2023-03-14 22:08:37
Python提供了两个内置函数从标准输入读入一行文本,默认的标准输入是键盘。如下:
1.raw_input
2.input
raw_input函数
raw_input() 函数从标准输入读取一个行,并返回一个字符串(去掉结尾的换行符):
str = raw_input("Enter your input: ");
print "Received input is : ", str
这将提示你输入任意字符串,然后在屏幕上显示相同的字符串。当我输入"Hello Python!",它的输出如下:
Enter your input: Hello Python
Received input is : Hello Python
input函数
input() 函数和raw_input() 函数基本可以互换,但是input会假设你的输入是一个有效的Python表达式,并返回运算结果。这应该是两者的最大区别。
str = input("Enter your input: ");
print "Received input is : ", str
这会产生如下的对应着输入的结果:
Enter your input: [x*5 for x in range(2,10,2)]
Recieved input is : [10, 20, 30, 40]
标签:Python,读取,键盘输入
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server 查询分析器快捷键集合
2007-08-17 09:42:00
引起用户注意的界面方式
2007-10-07 21:17:00
![](https://img.aspxhome.com/file/UploadPic/200710/7/2007107212329681s.jpg)
Python更换pip源方法过程解析
2022-01-20 08:00:58
![](https://img.aspxhome.com/file/2023/5/78745_0s.png)
AES算法 asp源码
2009-08-28 13:05:00
Pandas实现DataFrame按行求百分数(比例数)
2022-10-23 10:49:01
Oracle 数组的学习 小知识也要积累,养成好的学习态度
2009-08-04 12:42:00
Python模拟百度登录实例详解
2023-07-18 19:06:46
Oracle跨数据库查询并插入实现原理及代码
2024-01-14 18:52:58
python基于tkinter制作下班倒计时工具
2022-09-17 00:43:36
![](https://img.aspxhome.com/file/2023/9/87889_0s.jpg)
Python实现发送QQ邮件的封装
2022-10-08 21:19:56
![](https://img.aspxhome.com/file/2023/9/97269_0s.jpg)
Google投放广告的js的分析
2008-07-15 11:34:00
插件导致ECharts被全量引入的坑示例解析
2024-04-19 09:42:21
![](https://img.aspxhome.com/file/2023/0/136410_0s.png)
微信小程序获取当前位置的详细步骤
2024-04-08 10:52:09
![](https://img.aspxhome.com/file/2023/8/136988_0s.jpg)
JS+HTML5实现上传图片预览效果完整实例【测试可用】
2024-04-17 10:41:20
ASP模拟MVC模型的编程方式
2008-10-15 14:51:00
python使用Pycharm创建一个Django项目
2023-11-01 22:33:13
![](https://img.aspxhome.com/file/2023/4/110054_0s.png)
新手必备Python开发环境搭建教程
2023-07-09 03:25:35
![](https://img.aspxhome.com/file/2023/6/109366_0s.png)
Python数据分析之PMI数据图形展示
2022-06-19 07:18:23
![](https://img.aspxhome.com/file/2023/7/115607_0s.webp)
SaaS中的用户体验设计
2009-05-20 12:28:00
![](https://img.aspxhome.com/file/UploadPic/20095/20/p2009520103356-74s.jpg)
golang指数运算操作
2024-01-30 22:35:53