Why is the output of following code 0 instead of no output??? the program will print all ts in x but return nothing...ūüė• | Sololearn: Learn to code for FREE!
+ 1

Why is the output of following code 0 instead of no output??? the program will print all ts in x but return nothing...ūüė•

def print_num(x): for t in range (x) : print (t) return print_num(10)

26th Oct 2016, 5:29 AM
Manish27
Manish27 - avatar
5 Respuestas
+ 3
You don't need return here. Usually functions with more than one arguments there we need return because Return statement often used to return some result, some decision making. check this example def max(x, y): if x >=y: return x else: return y print(max(4, 7)) z = max(8, 5) print(z)
26th Oct 2016, 6:02 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 1
Just simply remove return statement because when function return any value it stop executing.
26th Oct 2016, 5:52 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 1
You are always welcome Manish
26th Oct 2016, 6:10 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
0
yeah , I got it mate but it return nothing!!!
26th Oct 2016, 5:54 AM
Manish27
Manish27 - avatar
0
ūüĎć thanks mate
26th Oct 2016, 6:06 AM
Manish27
Manish27 - avatar