Notification texts go here Contact Us Buy Now!

Why do I get None in output in second line while using eval function?

When you try to get the evaluation of something like eval("2") you are actually going to get type int.

But trying to evaluate print expression gives you None type. Print will be executed but type of eval("print(2+3)") will be None.

This is because you are giving eval() within print().

eval("(2 +3)")

This will return 5 as the function eval returns the value 5 which gets printed using the print()

However,

print(eval("print(2 +3)"))

Here inside the eval() you have used print(). So the inner print() prints the value 5 and the function eval() returns None as it has nothing to return. That None gets printed by the outer print()

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.