Functions

Why exactly would we want to use return in python for example in this code:

weather_data = [‘Sunny’, ‘Sunny’, ‘Cloudy’, ‘Raining’, ‘Snowing’]

def threeday_weather_report(weather):
first_day = " Tomorrow the weather will be " + weather[0]
second_day = " The following day it will be " + weather[1]
third_day = " Two days from now it will be " + weather[2]
return first_day, second_day, third_day

I don’t really see what return first_day, second_day, third_day will do and why I would want to use return here.

Well, how else are you going to get any output - in any form - from that function? :slight_smile:

3 Likes

Since the variables are defined inside the func threeday_weather_report():

You will need to use the return when calling the variables for any reason, without it you would not get any sort of

output for the function.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.