What is Print and Return Function and difference between them in Python

preview_player
Показать описание
What are functions?
Think of functions like mini-programs within your main program. They encapsulate specific tasks, allowing you to reuse code and keep your program organized and efficient. Imagine a chef following a recipe. Each step in the recipe can be seen as a function, performing specific actions like chopping vegetables or preheating the oven.

What is print?
print is a built-in function in Python that displays text to the console. It's like the chef announcing their progress, saying "Vegetables chopped!" or "Oven preheated!". print doesn't affect the flow of your program; it simply outputs information for you to see.

What is return?
return is another built-in function, but it plays a different role. It allows a function to send back a value after completing its task. Imagine the chef handing you a delicious plate of food after following the recipe. The return statement is like the chef handing you the completed dish, allowing you to use its value (the delicious food) elsewhere in your program.
Рекомендации по теме