6 Years
Discussion Span
Last Post by sunfutbol

Just use raw_input like you say yourself.

name = raw_input('Enter a name\n')

What is your problem, actually?


Im actually a beginner and was jus curious to know if using only input and then type casting it to string was possible...was jus trying to do something like this, for example ;

>>> input()
3 * 4 ** 5

This cant be done with rawinput, so was just wondering...


In Python2 the input() function actually uses raw_input() and eval().
You can enter a string with input() if you put it in quotes.
The function eval can turn evil if you enter a command to whipe out your hard disk for instance.

With Python3 raw_input() turns into simply input() and gives a string, thus eliminating the dangers of eval().

Edited by HiHe: eval


My advice, in Python2 it is better not to use the input() function. If you don't want to type raw_input all the time start your code with something like this ...

>>> input = raw_input
>>> name = input("Enter your name: ")
Enter your name: Clark Kent
>>> name
'Clark Kent'

... now you are in line with Python3 syntax.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.