简体   繁体   中英

Why does python print even if I don't type print?

print "a"; "b"

Will output:

"a"
'b'

Simply typing an int or string into the console will cause it to print.

1

Will output:

1 

Is there a reason or benefit for this?

The interactive Python interpreter is a REPL :

a simple, interactive computer programming environment that takes single user inputs (ie single expressions), evaluates them, and returns the result to the user

What you are seeing is the return value for each statement. Consider a slightly less simple example where the return value is different from the input:

>>> 2 + 3
5

The tight feedback loop provided by a REPL can be especially helpful when exploring a new language or problem domain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM