Python Evaluation HackerRank Solution

Hello Programmers, In this post, you will know how to solve the Python Evaluation HackerRank Solution. This problem is a part of the HackerRank Python Programming Series.

Python Evaluation HackerRank Solution
Python Evaluation HackerRank Solutions

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Python Evaluation HackerRank Solution


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

Task :

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.

Constraints :

Input string is less than 100 characters.

Sample Input :

print(2 + 3)

Sample Output :


Python Evaluation HackerRank Solutions


Disclaimer: The above Problem (Python Evaluation) is generated by Hackerrank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Next: Athlete Sort in python HackerRank Solution

Leave a Reply

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