Can we use 'input' instead of 'raw_input', I tried 2.6 and 3.3 versions and 'input' seems to work on both. Just a thought
Of course you can. The only difference is that by using raw_input you are always getting a string value as an input which you must convert/cast to the required type. Also, I believe that raw_input does not exist in Python v3.x. It has been renamed to input(). The following are true for Python v2.x. On the other hand input will evaluate whatever you pass in. So if you pass in a number (and the input function can understand that it is a number) you will get an int value back, where with raw_input you would get a string representation of the int value. Therefore, if you pass the number 3 to input function, you will get back the int 3. If you pass the same value to raw_input, you will get back the string '3'. In order to get the integer value of it, you can do int(raw_input('give me an integer: ')) In general I would suggest you use raw_input!
But, if you are using Python3.3 raw_input generates an error
Yes cause it doesn't exist. It has been replaced by input() function!
OK Thanks
No problem at all!
@Chris2332 you siad that in general you would suggest raw_input over input...why? i mean input basically (as i understand )recognises whatever u type....why should i use a func that sees everything as a string unless i tell it to see it as smthing else?
I was thinking something along those lines, if 3.3 only has 'input' and it recognizes everything as is, then surely, as someone new to Python I should use that ?
In Python2.x raw_input works like input does in Python3.x. 2.x is a different thing altogether.
@MicroBot I would suggest raw_input so you are always certain that the function always returns a string and then you manipulate it the way you want. So you cast it as you see fit or use it any way you might want. The control is yours effectively
Join our real-time social learning platform and learn together with your friends!