Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Hey Readers!!
While working on Python, you've used the input function and raw_input Python to take the user's desired input.
But have you ever wondered how the raw_input function is different from the input function?
Let's begin to learn more about this!!
raw_input Python
raw_input is an inbuilt function in python 2, which is used to get the input from the user, and it will take the input exactly typed by the user and pass it back as a string value.
Syntax
Variable name= raw_input()
Here,
Variable name: The name of variable you want to use.
raw_input(): The function takes the input and returns the value in an integer.
input function Vs. raw_input function
Both functions are used to take input from the user.
In the raw_input function, the data entered by the user is explicitly converted into a string, and it will return the string as the output.
In the input function, if the user input and the type are in integer type or list, it will only take the type as integer or list.
The raw_input function is used in python 2 only, and this function is not supported in python 3.
The input function is used in both python 2 and 3.
Let’s look at the examples for more understanding
Python 2
Let’s begin to understand raw_input in python 2 with the help of an examples
Code
ninjas = raw_input("Hey Ninjas!! Enter your name")
print(type(ninjas))
print(ninjas)
You can also try this code with Online Python Compiler
In the above example, the user has input the mobile number, an integer type input, but the raw_input function explicitly converts the input data into a string.
In the above example, there is an error because the raw_input function is not supported by Python 3.
Frequently Asked Questions
Can we use the raw_input function in python 3?
No, the raw_input function is not supported in python 3. To take the input from the user, the raw_input has to be replaced by the input function.
How to input multiple times in Python?
To input, multiple times in Python, Use the split() function.
What are the types of inputs in Python?
There are only two types of input in Python: raw_input function and input function.
What are lists in Python?
Lists in Python are used to store multiple values into a single variable.
What are functions in Python?
A function known as a block of code that only executes when it is being called.
Conclusion
This blog has extensively discussed raw_input Python. This article helped enhance your knowledge about the difference between the raw_input function and the input function in Python.
If you want to learn more deeply, check out the excellent content on the Coding Ninjas Website: