The eval() function evaluates/executes an expression passed as a string, or as a code object generated by the compile function.

The function evaluates the input expression  and returns the yielded value.

Syntax:

eval(expression)
Examples with strings:
eval("1 + 2")
//3
eval("9//3")
//3
eval("(7-8)*2")
//-3
eval("len('Hello, World!')")
//13
eval("'Hello ' + 'World!'")
//'Hello World!'
Examples with code objects:

The built-in compile function can be used to compile into Python code a String containing valid expression, we can then use the eval() function to execute the code object. Examples:

string = "1 + 2 + 3"
code_object = compile(string, '', 'eval')#the 'eval' arguments tells Python that we will execute this code object using the eval()b function
eval(code_object)
//6
string2 = "len([1, 2, 3, 4, 5])"
code_object2 = compile(string2, '', 'eval')
eval(code_object2)
//5

The function can especially be useful when using Python interactively, as it can be used to evaluate expressions entered by the user directly.  Example:

def evaluator():
     expression = input("Enter an expression:")
     while(expression.strip().lower() != 'exit'):
         try:
             print(eval(expression))
         except:
             print("oops! invalid expression: %s"%expression)
         expression = input("Enter an expression:")
     else:
        print('See you later!')

evaluator()
//Enter an expression:1 + 1
//2
//Enter an expression:5 + 6
//11
//Enter an expression:7 * 8 - 2
//54
//Enter an expression:8 [ 6
//oops! invalid expression: 8 [ 6
//Enter an expression: exit
//See you later!

The function can also be useful when a script needs to evaluate an expression or expressions stored in a file.

Although the eval() function can be powerful and useful, it should be used with caution as it can cause security issues. It is important to evaluate expressions from protected sources and context-aware code.