Functions without a return statement don’t return any value. However, strictly speaking, they return a None value, which practically represents the absence of a value. The None value is an instance of the NoneType data type
Since it doesn’t return any value it returns None. So yes, you are right.
If you add a return statement instead of print(), it will return float. So yes, you are right again.
I hope you have already tried and figured it out by yourself.
Yes, I’ve tried but I wanted to make sure I am right.
Thanks a lot.
And here, how the type of x is NoneType although 3.14 is assigned to x?
And why the output of j=print_constant() is 3.14 and the output of print(j) is None?
Have a look again at your code. Are you finding the type of x?
What is assigned to j?
This might help you find the answer by yourself.
If that didn’t help, here is the explanation
Since your function doesn’t have a return type, it will return None which you already know. So when you assign print_constant() to the variable j, the function gets executed and store None value to the variable j. But since the function has a print statement inside of it, it will print whatever it is supposed to print. But the value it stores and returns is None.
So the first line you see on the output 3.14 is the result of print statement and the second line None is the actual value stored in j.
When you get the type of j it obviously returns None type.
You can also see that the variable x defined inside the function doens’t really come in the picture. I hope this gives you a better idea.