Python raw_input()

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值