0
Can Any one tell me why it is getting error, if we put "print" in place of "return"?
def lang(ext): if ext == ".py": return "Python" elif ext == ".js": return "JavaScript" elif ext == ".html": return "HTML" elif ext == ".css": return "CSS" elif ext == ".c": return "C" else: print("enter valid extention: ") print("The Extention You Entered Is "+ lang(input("Enter An Extention: \n")))
7 Answers
+ 6
When the function call doesn't reach any return statements it returns None instead.
The error was raised by a concatenation with string and None.
+ 3
This is what causes the error:
"The Extension You Entered Is " + None
+ 3
Mr. 12 Yes, it would fix the error.
+ 1
Mr. 12
Another thing you need to understand about return is that it won't go further down if the return condition is met.
For example:
def test(num):
if num == 3:
return True
print("yes")
print (test(3))
Output: True
yes won't print because return acts like break in a loop
Hope you understand đđ
+ 1
Seb TheS thank you bro.
0
Seb TheS can u please explain briefly
0
Seb TheS you are saying that, we hvae to convert the input into string! right?