Notification texts go here Contact Us Buy Now!

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

When attempting to evaluate expressions like eval("2"), the result is an integer. However, evaluating a print expression yields a None type. The print command is executed, but eval("print(2+3)") returns None.

This is because the print() function is being called within eval():

eval("(2 +3)")

In this case, the eval() function returns the value 5, which is then printed out. However, when you use:

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

The eval() function is only evaluating the inner print statement, which prints the value 5. The eval() function itself does not return a value, so the outer print statement prints None.

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.