标签:turn local ase return The ide sid turned res
1. eval() : the eval function evaluates the “String” like a python expression and returns the result as an integer
Syntax: eval(expression, [globals[, locals]])
The arguments or parameters of eval function are strings, also optionally global and locals can be used as an argument inside eval function, but the globals must be represented as a dictionary and the locals as a mapped object.
Difference between the input() and eval(): input() takes the user input, but when the user enters an integer as an input the input function returns a string, but in the case of eval it will evaluate the returned value from a string to an integer. E.g:
input = input("Enter any number of your choice:")
print(input)
print(type(input))
--------------------------------------------------------------------Enter any number of your choice: 10 + 10
10 + 10
<class ‘str‘>
eval = eval(input("Enter any number of your choice"))
print(eval)
print(type(eval))
--------------------------------------------------------------------Enter any number of your choice: 10 + 10
20
<class ‘int‘>
闷了请做题
标签:turn local ase return The ide sid turned res
原文地址:https://www.cnblogs.com/noralee/p/12601885.html