Online Tutorials & Training Materials | STechies.com
Register Login
Advertisement

Python Input vs Raw_Input

|| 0

Python Input vs Raw_Input
Stechies

What is Python RAW_INPUT Function?

The raw_input function in Python is used to accept input values from the user that can be used for other operations. When the function is used, the raw_input waits for the user to enter a value and then hit enter. The input can be stored in the form of a string in a variable.

Here the user input is not interpreted by the function. For example, if the user provides an integer as input, raw_input() will take it and convert it into a string before returning it.

Python Raw_Input Function Examples

name = raw_input("Please Tell me your name? ")

print "Hello, %s." %name

What is Python INPUT Function?

Input() function is available with Python 3, input taken as a raw input after performing evaluation function using ‘ eval()’ on input and return exactly. Means Python automatically identifies for a string, integer, float, and a list and return respectively.

Python  Input Function example

name = input("Please Tell me Your name? ")

print("Hello, %s." %name)

Reading Input from Keyboard for Python 2

The two methods to accept input from the keyboard in Python 2 are:

input() function – This is used to take an user input and type of input that is provided and return it without modifying the data.

raw_input() function - This is used to take an user input and convert it into string explicitly.

Reading Input from Keyboard For Python 3

In Python 3, input from the user is accepted through the input() function and raw_input() is removed. In the input() function here accepts the input, converts it into a string and returns it after removing the newline.  


Advertisement
Advertisement
Advertisement