Examveda

What will be the output of the following Python functions?
x=3
eval('x^2')

A. Error

B. 1

C. 9

D. 6

Answer: Option B

Solution (By Examveda Team)

The eval() function in Python evaluates the specified expression, which is a string, and returns the result. In this case, the expression 'x^2' is evaluated. However, the ^ operator in Python represents bitwise XOR, not exponentiation. So, 'x^2' evaluates to 3⊕2=6 in bitwise XOR. Therefore, the output of the function call eval('x^2') will be 6.

This Question Belongs to Python Program >> Python Built In Functions

Join The Discussion

Related Questions on Python Built In Functions