I have a very basic query regarding Python (2.7.3) strings. What is the difference to the Python interpreter between
someString = 'foo bar'
someString
and
print someString
The first one produces 'foo bar'
and the second produces foo bar
.
I have a very basic query regarding Python (2.7.3) strings. What is the difference to the Python interpreter between
someString = 'foo bar'
someString
and
print someString
The first one produces 'foo bar'
and the second produces foo bar
.
Just someString
will do mostly nothing but return the someString value. In the interactive interpreter, return values cause the interpreter to print the repr
value of it. repr(someString)
will result in 'foo bar'
a representation of the string that is itself valid Python code. If you don’t run it with an interactive interpreter, that line will simply return the string’s value but otherwise do nothing (i.e. the value is then thrown away).
The print statement will however execute the statement and print the value to the standard system output, usually your console window. So in a non-interactive interpreter session, this is something you will still see.