EvilZone
Programming and Scripting => Scripting Languages => : 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?
-
Your book is most likely python3 book ?
-
doesnt matter... i ve changed to python 3, but why in python 2.7 you have to use raw_input?
-
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.
-
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.
-
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!
-
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?
-
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
-
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
-
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!')