EvilZone

Programming and Scripting => Scripting Languages => : FiCl July 08, 2014, 02:43:43 PM

: raw_input?
: FiCl July 08, 2014, 02:43:43 PM
i ve just started learning Python in which i switched from Java as my first programming language. Ive downloaded Python 2.7, and it took me a while to find out that i have to use raw_input if im going to type something that it isnt a number. I was really confused because the book i was reading had input instead of raw_input. Is there something i am doing wrong? or i have to use raw_input in Python 2.7?
: Re: raw_input?
: gray-fox July 08, 2014, 03:04:46 PM
Your book is most likely python3 book ?
: Re: raw_input?
: FiCl July 08, 2014, 03:18:06 PM
doesnt matter... i ve  changed to python 3, but why in python 2.7 you have to use raw_input?
: Re: raw_input?
: Kulverstukas July 08, 2014, 03:26:09 PM
doesnt matter... i ve  changed to python 3, but why in python 2.7 you have to use raw_input?
There's nothing else to use.
: Re: raw_input?
: FiCl July 08, 2014, 03:31:40 PM
There's nothing else to use.
no...i didnt know at first i was using Python 2 so i used input.. It worked, but it allowed me only to enter numbers.
: Re: raw_input?
: XxCyberTheifxX July 08, 2014, 03:32:53 PM
Ok, Python was my first language, but coming from Java I can see how this is confusing. In python, input refers to you need the user to input a number, nothing else. raw_input on the other hand, allows them to input a string value, which is more useful if you were foresay, asking their name. Hope this helps!
: Re: raw_input?
: FiCl July 08, 2014, 03:34:22 PM
Ok, Python was my first language, but coming from Java I can see how this is confusing. In python, input refers to you need the user to input a number, nothing else. raw_input on the other hand, allows them to input a string value, which is more useful if you were foresay, asking their name. Hope this helps!
so use input if i know the user will input a number or use raw_input always?
: Re: raw_input?
: gray-fox July 08, 2014, 03:37:35 PM
Ok, Python was my first language, but coming from Java I can see how this is confusing. In python, input refers to you need the user to input a number, nothing else. raw_input on the other hand, allows them to input a string value, which is more useful if you were foresay, asking their name. Hope this helps!
But in Python 3 raw_input( ) is just input(). It was renamed .Right?

Lähetetty minun GT-I9300 laitteesta Tapatalkilla
: Re: raw_input?
: FiCl July 08, 2014, 03:52:22 PM
But in Python 3 raw_input( ) is just input(). It was renamed .Right?

Lähetetty minun GT-I9300 laitteesta Tapatalkilla
i dont know, because in Python 2.7 you can use both input and raw_input
: Re: raw_input?
: TheWormKill July 10, 2014, 06:42:05 PM
In Python 2.x there are input() (taking only numbers, not recommended to use) and raw_input() (returning string which you can process further). However, Python3 hasn't raw_input, it was renamed to input, since the functionality of the old input can be replaced by a bit more code.
:
try:
     num = int(input('Enter a number: '))
except:
     print('Couldn\'t convert input to Integer!')