top of page

Keep Reading !

You can also checkout more topics like...

peep-101_edited.png
EXPLORE COURSES (6).png
EXPLORE COURSES (9).png
EXPLORE COURSES (7)_edited.jpg

Difference between input() and raw_input() in Python

Programmers frequently have a need to connect with users, either to get information or to give a type of result. Most programs today utilize a dialogue box as a method of requesting the user to give some sort of input. While python gives us two inbuilt functions to peruse the input from the keyboard.

input() function


input() function is utilized to take the qualities from the client. This function is called to advise the program to pause and trust that the client will input the qualities. It is an implicit function. The input() function is utilized in both the rendition of Python 2.0 and Python 3.0. In Python 3.0, the input function explicitly changes over the input you provide for the typed string. Be that as it may, the Python 2.0 input function takes the worth and sort of the input you enter all things considered without modifying the sort.


Follow the example below:



# input() function in Python3.0


first_value = input("Your Name: ")

# print the type of input value
print(type(first_value))
print(first_value)


second_value = input("Your Age: ")
print(type(second_value))

second_value = int(second_value)
print(type(second_value))
print(second_value)

OUTPUT



raw_input() function


Python raw_input function is utilized to get the values from the User. We call this function to advise the program to pause and trust that the User will input the values. It is an implicit function. The input function is utilized uniquely in Python 2.0 variant. The Python 2.0 has two functions to take the values from the User. The first is input function and another is raw_input() function. The raw_input() function is like input() function in Python 3.0. Developers are prescribed to utilize raw_input function in Python 2.0. Since there is a weakness in input function in Python 2.0 adaptation.




advertisement








Follow the Example Below



# input() function in Python2.0


first_value = raw_input("Your name: ")
print(type(first_value))
print(first_value)

second_value = raw_input("Your age: ")
print(type(second_value))
val2 = int(second_value)
print(type(second_value))
print(second_value)




advertisement







423 views0 comments

Recent Posts

See All
bottom of page