About the difference between Python return and print

Source: Internet
Author: User

Conceptually, one is the return value, one is the printout.

Difference One: Return is the end of the function is usually placed in the end, when you write back after the return of something is not performed the following

def   Renshu (x, y):     h=x+y     print (h)     return  H      print (' Hello  word ') print (Renshu (3,7))

The result after execution is that Hello word does not execute. No error.

C:\Python34\python.exe c:/users/administrator/pycharmprojects/python/class/suibi.py
10
10


1 C:\Python34\python.exe c:/users/administrator/pycharmprojects/python/class/suibi.py  2 3 10
The difference two returns the result of return can be called in Don't go like do add
 
def ,y):
h=x+y
print (h)
return h
print ( ' hello word ')


print (Renshu (,7))

x= (Renshu (3, 7) +10
print (x)


Execution results are
C:\Python34\python.exe c:/users/administrator/pycharmprojects/python/class/suibi.py
10
10
10
20

Process finished with exit code 0

Print just prints no results
def   Renshu (x, y):
H=x+y
Print (h)




Print (Renshu (3,7))

X= (Renshu (3,7)) +10
Print (x)

Error message

None
File "c:/users/administrator/pycharmprojects/python/class/suibi.py", line A, in <module>
10
X= (Renshu (3,7)) +10
typeerror:unsupported operand type (s) for +: ' Nonetype ' and ' int '

Process finished with exit code 1

About the difference between Python return and print

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.