>> print "hello world" hello world >>> "hello world" 'hello world' >>> What is the difference?...">

Python print "hello world" vs "hello world"

>>> print "hello world"
hello world
>>> "hello world"
'hello world'
>>> 

What is the difference?

Full question about noob.

Python hello world example mainly uses

print "hello world"

Can I remove this printand just use "Hello world"python for input?

+4
source share
8 answers

The difference is what printcauses str, while the REPL action (reading evaluates the print cycle) by default means calling the reprobject if it is not None.

Please note that if you are not working in an interactive interpreter (you are not in the REPL), you will not see any output in the version without print.

, . repr .

+10

, , REPL.

>>> print "hello\nworld"
hello
world
>>> "hello\nworld"
'hello\nworld'

"hello\nworld"

,

+2

Bash, echo '$ HOME', $HOME , $HOME, /home/user/.

Python, , . ", , . , \".

-

print 'hello\nworld' -> hello
                        world

print "hello\nworld" -> hello
                        world

'hello\nworld' -> hello\nworld

, .

, . -

print repr("hello\n\tworld\\") -> 'hello\n\tworld\\'

.

/ . .

0

, , , , Python. -, .

1

>>> print "hello world"
hello world

, , , .

2

>>> "hello world"
'hello world'
>>> 'hello world'
'hello world'

, , / , . , .

Python. , .

0

def greet(): print ("",)

()

:

('',)

, ?

0

(", ")

,

0

Python.

print "hello world" , print , stdout https://docs.python.org/3/library/functions.html#print

>>> "hello world"- just let the python interpreter excuse the line of code, which is just a line. Since you are working on python, an interactive shell. The shell displays the string "Hello world."

0
source

You can refrain from using the print function if you are on the command line, otherwise you must use the print function

-1
source

All Articles