IN PYTHON
- Use the eval() function to evaluate these strings as Pythonexpressions. In a commented section of your file, explain what theresults are, which ones result in an error, and why that erroroccurred.
a. ‘2 * 3 + 1’
b. ‘hello’
c. “‘hello’ + ‘ ‘+ ‘world!'”
d. “‘ASCII’.count(‘I’)”
e. ‘x = 5’
Answer
eval() – Evaluates the code given in string format to it.
a). eval(‘2*3+1’)
This evaluate the expression 2*3+1 which 2 multiplied by 3 andadded with 1. So the answer is 7.
b). eval(‘hello’)
Here there is no expression, but only single word hello isgiven. So compiler looks for a variable called hello, which is notdefined. So
OR
OR