>>> print "hello world"
hello world
>>> "hello world"
'hello world'
>>>
What is the difference?
The Python Hello, World! example mostly uses:
print "hello world"
Can I strip that print
and just use "Hello world"
for giving a Python introduction?
The difference is that print calls str whereas the default action of the REPL (read evaluate print loop) is to call repr on the object unless it is None .
Strings in python are surrounded by either single quotation marks, or double quotation marks. 'hello' is the same as "hello".
Source Codeprint('Hello, world! ') Hello, world! In this program, we have used the built-in print() function to print the string Hello, world! on our screen.
Python Hello world program uses the print function to print hello world. That will be visible on the output screen. The basic way to produce an output in python programming is by using the print() function, where you can pass none or more expressions separated by commas.
The difference is that print
calls str
whereas the default action of the REPL (read evaluate print loop) is to call repr
on the object unless it is None
.
Note that if you aren't working in the interactive interpreter (you're not in the REPL), then you won't see any output in the version without print
.
Also note that there is a difference between the output. repr
adds quotes on strings.
If you substitute the space for a newline, you'll see they don't even really work the same in the REPL.
>>> print "hello\nworld"
hello
world
>>> "hello\nworld"
'hello\nworld'
If you try to use
"hello\nworld"
by itself in a program, you will get no output of course
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With