Digging into python : Part 3 | Accepting input from user

input() vs raw_input()

When I started do programming in python, I was not aware that there are two functions for accepting input from the user during run time. input() was the only function that I was aware of and it felt little difficult when I wanted to accept string from user. All the strings should be enclosed with "" or ' '. So basically the difference between this two functions are, when we take an input from user using input(), the data type of the variable will be dynamically given. If we enter a number 6, the data type of the variable which receives the data will be int. If the received data have decimal points then the data type of the variable will be float. Same will happen for a string input. So the data type of the receiving variable will change according to the data that user enter. That was the case in input(). 
In raw_input() what ever the user enters the data type of the receiving variable will be string. If we enter 6 or 6.5 it will be treated as string only. Below are some screenshots that prove what I told.. 😊


Comments

Popular Posts