Good day, learners. In our previous tutorial we learned about Python SimpleHTTPServer. In this tutorial we will learn about Python raw_input() function.

美好的一天,学习者。 在上一教程中,我们了解了Python SimpleHTTPServer 。 在本教程中,我们将学习Python raw_input()函数。

Python raw_input() (Python raw_input())

Actually, Python raw_input() function is removed from Python 3.x versions. But it exists in Python 2.x. Actually it has same functionality same as python input() function of Python 3.x.

实际上,Python raw_input()函数已从Python 3.x版本中删除。 但是它存在于Python 2.x中。 实际上,它具有与Python 3.x的python input()函数相同的功能。

However, in this tutorial we will try to enlighten on this topic so that you would not surprise if you find raw_input function in python 2.x code. It will also help you if you are migrating your code from python 2 to python 3.

但是,在本教程中,我们将尝试启发该主题,以便在python 2.x代码中找到raw_input函数时不会感到惊讶。 如果要将代码从python 2迁移到python 3,它也将为您提供帮助。

Python 2.x环境设置 (Python 2.x environment setup)

To use python raw_input() function, you must have python 2 installed in your system. If you run your program from terminal, then use python2 instead of python or Python3. So the sample command to execute is given below:

要使用python raw_input()函数,必须在系统中安装python 2。 如果从终端运行程序,请使用python2而不是pythonPython3 。 因此,下面给出了要执行的示例命令:

$python2 sample.py

It depends on how you have configured your python. Bottom line is that if you are using raw_input function, you have to run your program using python 2.x version.

这取决于您如何配置python。 底线是,如果您使用raw_input函数,则必须使用python 2.x版本运行程序。

If you use PyCharm IDE, then you can change your python compiler. To do so, go to File -> Settings -> Project -> Project Interpreter. Then select python 2.x. from the list. Same as the below image.

如果您使用PyCharm IDE,则可以更改python编译器。 为此,请转到文件->设置->项目->项目解释器 。 然后选择python2.x。 从列表中。 与下图相同。

Python raw_input示例 (Python raw_input example)

Here, we will introduce a single python raw_input example program. But you should know at first that the raw_input() function takes string as input. So, we will now write a program that will prompt for your name and then prints it. The code is given below.

在这里,我们将介绍一个单独的python raw_input示例程序。 但是您首先应该知道raw_input()函数将字符串作为输入。 因此,我们现在将编写一个程序,提示您输入名称,然后将其打印出来。 代码如下。

a = raw_input('What\'s your name : ')
print 'Username : ', a

Look at the print function closely. The whole code is written for python 2.x version. So, some functions may not seem familiar to you now. However, the output of the code will be like below.

仔细查看打印功能。 整个代码是针对python 2.x版本编写的。 因此,您现在似乎对某些功能不熟悉。 但是,代码的输出将如下所示。

What's your name : Andy Moore
Username :  Andy Moore

So, that’s all about python raw_input() function. Hope that you get the basic concept about the function.

所以,这一切都与python raw_input()函数有关。 希望您了解有关该功能的基本概念。

Reference: Official Documentation

参考: 官方文档

翻译自: https://www.journaldev.com/15931/python-raw-input

Python raw_input()相关推荐

  1. Python eval()函数的使用

    Python eval()函数的使用 文章目录 一.官网给出的定义 1.eval() 方法的语法: 二.eval的作用 1.计算字符串中有效的表达式,并返回结果 2.将字符串转成相应的对象(如list ...

  2. Python xrange()函数

    Python xrange() function is used to generate a sequence of integers. This function is part of Python ...

  3. Python ord(),chr()函数

    Python ord() and chr() are built-in functions. They are used to convert a character to an int and vi ...

  4. Python bytearray()

    Python bytearray() function returns a bytearray object that contains the array of bytes from the inp ...

  5. Python complex()

    Python complex() function is used to create complex numbers. It's a built-in function that returns a ...

  6. Python Frozenset()

    Python frozenset is an unordered collection of distinct hashable objects. Frozenset is an immutable ...

  7. Python strftime()

    Python strftime() function is present in datetime and time modules to create a string representation ...

  8. Python sorted()函数

    Python sorted() function returns a sorted list from the items in the iterable. Python sorted()函数从ite ...

  9. Python format()函数

    Python format() function is used to convert given object into string representation based on the pro ...

最新文章

  1. Jzoj4209 已经没有什么好害怕的了
  2. 武汉linux驱动培训转让,linux驱动培训靠谱吗
  3. GO结构体之间的转换
  4. 海量特征按照缺失值null/NAN数量异同进行分组归类
  5. c语言 指针到字符串,C语言中的指针和字符串
  6. 工作394-注册页面学习
  7. 多个 VUE 前端工程部署设置、nginx 代理配置
  8. 关于SpringBoot下template文件夹下html页面访问的一些问题
  9. spark应用程序的运行架构(简单到复杂)
  10. 淘宝京东卖家可以用到的小工具和素材资源网站
  11. nginx与IIS服务器搭建集群实现负载均衡(一)
  12. 日本用活体肌肉构建机械臂,人类与机器融合取得新突破
  13. 如何检查视频画面延迟的时间
  14. VM虚拟机浏览器替代软件-VMLogin虚拟多登指纹浏览器,超级浏览器,防关联浏览器
  15. 「面试」TCP/IP常见攻击
  16. 键盘上每个键作用!!! (史上最全的)
  17. 成都购房:2019年成都限购限贷政策
  18. 直方图均衡--对比度调整和去雾效果
  19. Java开源的11个中文分词器使用方法和分词效果对比
  20. 《复杂系统突现论》读后

热门文章

  1. Ruby on Rails,创建模型,附赠模型与表名不一致时的解决方法
  2. WebService远程调试
  3. FPGA内部资源总结
  4. Python脚本-导出SQL查询结果到Excel文件
  5. A星寻路算法(A* Search Algorithm)
  6. Java零基础系列001——第一个程序
  7. No Pain No Game
  8. 数据结构上机实践第十周项目2 - 用二叉树求解代数表达式
  9. 自动驾驶算法-滤波器系列(四)——不同运动模型在KF/EKF中的应用
  10. LabView学习笔记(二):滤波器实验