Python Forum
Need of return in function if statement inside the function already returns
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need of return in function if statement inside the function already returns
#1
Hello,

I'm learning python from some online tutorials. When learning about function, there was an exercise to check "Given two integers, return True if the sum of the integers is 20 or if one of the integers is 20. If not, return False"

Before making function, i did following

a = (10, 20) 
sum(a) == 20 or a[0] == 20 or a[1] == 20
and it returns True if conditions satisfy.

but when I tried to make this in to a function

def func(a):
    sum(a) == 20 or a[0] == 20 or a[1] == 20
when called the above function
func((10,20))
. It didn't return anything. I had to put return inside the function to get True or False.

What is the need of this return since
sum(a) == 20 or a[0] == 20 or a[1] == 20
this line can already return true or False on it's own???
Thanks
Reply


Messages In This Thread
Need of return in function if statement inside the function already returns - by Athul - Aug-06-2018, 07:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Use of function/return Paulman 6 2,421 Oct-24-2021, 11:07 PM
Last Post: Paulman
  Multiple return from function Grimmar 7 3,635 Mar-22-2021, 09:20 PM
Last Post: Grimmar
  GCF function w recursion and helper function(how do i fix this Recursion Error) hhydration 3 2,589 Oct-05-2020, 07:47 PM
Last Post: deanhystad
  Lambda function not return value mbilalshafiq 4 3,372 Jul-04-2020, 07:47 AM
Last Post: ndc85430
  Child class function of Log return "None" mbilalshafiq 2 2,260 Jun-30-2020, 07:22 PM
Last Post: mbilalshafiq
  Question on "define function"; difference between return and print extricate 10 4,816 Jun-09-2020, 08:56 PM
Last Post: jefsummers
  [split] problem with function return value ops 1 3,391 Apr-13-2020, 01:48 PM
Last Post: buran
  Function to return today's month, day, and year sbabu 9 5,010 Jan-28-2020, 06:20 PM
Last Post: snippsat
  Passing a function to another function yulfmd1802 3 2,266 Jan-23-2020, 09:13 AM
Last Post: ndc85430
  Adding a sqrt function syntax error and <build-in function sqrt> from tkinter import Kael 0 1,888 Oct-14-2019, 05:51 PM
Last Post: Kael

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020