Python Evaluation in Python | HackerRank Solution

Hello coders, today we are going to solve Python Evaluation HackerRank Solution in Python.

Python Evaluation in Python


The 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.

For example:

>>> eval("9 + 5")
>>> x = 2
>>> eval("x + 3")

Here, eval() can also be used to work with Python keywords or defined functions and variables. These would normally be stored as strings.

For example:

>>> type(eval("len"))
<type 'builtin_function_or_method'>

Without eval()

>>> 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.

Sample Input

print(2 + 3)

Sample Output


Solution – Python Evaluation in Python | HackerRank Solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
from __future__ import print_function

Disclaimer: The above Problem (Python Evaluation) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *