Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k points)

I want to get a string from a user, and then manipulate it.

testVar = input("Ask user for something.")

Can testVar be made a string without having the user to type his response in quotes? i.e. "Hello" vs. Hello

If the user types in Hello, the following error message appears:

NameError: name 'Hello' is not defined

1 Answer

0 votes
by (26.4k points)

Instead of using input(), you can use raw_input().

testVar = raw_input("Ask user for something.")

input() really assesses the input as Python code. I recommend never utilize it. raw_input() restores/returns the verbatim string entered by the user.

Are you pretty much interested to learn Python in detail? Register for the Python training course to gain more knowledge.

Browse Categories

...