eval function takes a String and evaluate the result.
Examples:
x = eval("10 + 20 + 30")
print(x)
Output:
60
--------------------------
x = eval(input("Enter Expression: "))
print(x)
Output:
Enter Expression: 10+20-5*10/2
5.0
-------------------------
eval() can evaluate the input to list, tuple, set, etc based on the provided input:
i = eval(input("Enter List: "))
print(type(i))
print(i)
Output
Enter List: [10,20,40]
<class 'list'>
[10, 20, 40]
Examples:
x = eval("10 + 20 + 30")
print(x)
Output:
60
--------------------------
x = eval(input("Enter Expression: "))
print(x)
Output:
Enter Expression: 10+20-5*10/2
5.0
-------------------------
eval() can evaluate the input to list, tuple, set, etc based on the provided input:
i = eval(input("Enter List: "))
print(type(i))
print(i)
Output
Enter List: [10,20,40]
<class 'list'>
[10, 20, 40]
No comments:
Post a Comment