Python Evaluation HackerRank solution
eval() expression is a very powerful built-in function of Python. It helps in evaluating an expression. The expression can be a Python statement, or a code object.
>>> eval("9 + 5") 14 >>> x = 2 >>> eval("x + 3") 5
eval() can also be used to work with Python keywords or defined functions and variables. These would normally be stored as strings.
>>> type(eval("len")) <type 'builtin_function_or_method'>
>>> type("len") <type 'str'>
You are given an expression in a line. Read that line as a string variable, such as var, and print the result using eval(var).
NOTE: Python2 users, please import
from __future__ import print_function.
Input string is less than 100 characters.
print(2 + 3)
#Python Evaluation HackerRank solution S=input() eval(S) #Python Evaluation HackerRank solution
Disclaimer: This problem is originally created and published by HackerRank, we only provide solutions to this problem. Hence, doesn’t guarantee the truthfulness of the problem. This is only for information purposes.