What is the difference between print and return in python

+2 votes
If we get the same output why not just use print?
May 23, 2019 in Python by Waseem
• 4,540 points

edited May 24, 2019 by Omkar 8,101 views

2 answers to this question.

+1 vote

Return statements end the execution of a function and if return is not given  by default it returns None.

Print statement shows the human user a string representing what is going on inside the computer

answered Aug 26, 2019 by anonymous
0 votes

Thats a very good question.

Fortunately, the answer is VERY simple. 

You see, A return statement is used to end the execution of the function call and “returns” the result (value of the expression following the return keyword) to the caller. The statements after the return statements are not executed. If the return statement is without any expression, then the special value None is returned.

On the other hand, print() is an INBUILT function in Python, originally written in C. So what that means is, it runs the program and outputs whatever is required it to do - in this case literally output what the user wants it to.

In other words, an if-else or a loop must return some value. in case nothing is mentioned, Python is smart enough to return None.

answered Aug 10, 2020 by Abin
• 140 points

Related Questions In Python

0 votes
1 answer

What is the difference between print and pprint in Python?

As per the documentation,  The pprint module provides a capability ...READ MORE

answered Jul 8, 2019 in Python by Arvind
• 3,050 points
6,934 views
+1 vote
1 answer

What is the difference between range and xrange functions in Python 2.X?

xrange only stores the range params and ...READ MORE

answered Aug 22, 2018 in Python by Priyaj
• 58,020 points
2,435 views
0 votes
5 answers
0 votes
0 answers

What is the difference between isdigit, isnumeric and isdecimal in python?

Can you give examples for each of ...READ MORE

May 31, 2019 in Python by Waseem
• 4,540 points
2,271 views
0 votes
1 answer

What is the difference between str() and repr() functions in Python?

str() is mostly used to create output ...READ MORE

answered Jul 8, 2019 in Python by Arvind
• 3,050 points
1,642 views
0 votes
1 answer

What is the key difference between self in ruby and self in python?

Ruby and Python are actually very different languages (although ...READ MORE

answered Jul 30, 2019 in Python by Mohammad
• 3,230 points
1,114 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,465 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,125 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP