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!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
+ 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