

The previous example we showed demonstrates this behavior. The input() function, by default, will convert all the information it receives into a string. Print( "Is this what you just said? ", txt)įrom here onwards this article will use the input method from Python 3, unless specified otherwise. # Note that in version 3, the print() function # requires the use of parenthesis. Txt = input( "Type something to test this out: ") Similarly, take a look at an example of input function in Python 3.

#Taking raw input in python to list stack overlofw code#
Is this what you just said? Let the Code be with you! Output Type something to test this out: Let the Code be with you! Txt = raw_input( "Type something to test this out: ") Take a look at an example of raw_input function in Python 2. To obtain the same functionality that was provided by Python 2's input() function, the statement eval(input()) must be used in Python 3. And the input() function of Python 2 is discontinued in version 3. In Python 3, raw_input() function has been deprecated and replaced by the input() function and is used to obtain a user's string through the keyboard. For Python 2, the function raw_input() is used to get string input from the user via the command line, while the input() function returns will actually evaluate the input string and try to run it as Python code. The difference when using these functions only depends on what version of Python is being used. Comparing the input and raw_input Functions On a curious note, little has changed in how this function works between Python versions 2 and 3, which is reflected in the workings of input() and raw_input(), explained in the next section. The entered string will simply be submitted to the application. While hitting the ENTER key usually inserts a newline character ("\n"), it does not in this case. To actually enter the data, the user needs to press the ENTER key after inputing their string. When one of the input() or raw_input() functions is called, the program flow stops until the user enters the input via the command line. These functions have an optional parameter, commonly known as prompt, which is a string that will be printed on the screen whenever the function is called.

To receive information through the keyboard, Python uses either the input() or raw_input() functions (more about the difference between the two in the following section). This article briefly explains how different Python functions can be used to obtain information from the user through the keyboard, with the help of some code snippets to serve as examples. Python, while comparatively slow in this regard when compared to other programming languages like C or Java, contains robust tools to obtain, analyze, and process data obtained directly from the end user. The way in which information is obtained and handled is one of the most important aspects in the ethos of any programming language, more so for the information supplied and obtained from the user.
