0

Why is "None" an output?

def max(x, y): if x >y: return x elif x==y: print("Equal") else: return y print(max(7,7))

13th Jun 2021, 8:45 AM
Kristóf Pintér
Kristóf Pintér - avatar
2 Antworten
+ 3
because instead of returning "Equal" you print it in the function... other statements are not executed since x==y, so value implicitly returned by function is None... the output is: Equal None
13th Jun 2021, 8:48 AM
visph
visph - avatar
+ 2
Kristóf Pintér , additional to the comments given by visph, you should NOT use " max" as a name for a user defined function. max() is a build-in function of python. using the same name for your own function can lead to trouble and may create problems that are not easy to catch.
13th Jun 2021, 9:48 AM
Lothar
Lothar - avatar