Home > Article > Backend Development > The difference between eval and int in python
What is the difference between eval and int in python? Let me introduce it to you below:
1.eval() function
eval(f7e83be87db5cd2d9a8a0b8117b38cd4) can be used as a Python expression The method parses and executes the string and returns the result output. The eval() function will remove the two quotes from the string and interpret it as a variable.
Function:
a. Processing numbers
Single quotes, double quotes, and the eval() function interpret them as int type; triple quotes are interpreted as str type.
b. Processing string type strings
For strings (non-numbers) in eval() brackets, if the string is in single quotes Or double quotes will cause NameError, because the eval() function will remove the two quotes when processing the string. Correctly, you should use a triple quote consisting of a single quote and a double quote to enclose the string.
Related recommendations: "Python Video Tutorial"
2.int() function
The int() function can Convert a number to an integer
>>> int('12',16) 18
There are two things to note here:
1) 12 must be entered in the form of a string, if it is with the parameter base
2) This is not about converting 12 into a hexadecimal number, but that 12 is a hexadecimal number, and the int() function represents it as a decimal number, as follows
>>> int('0xa',16) 10 >>> int('10',8) 8
The above is the detailed content of The difference between eval and int in python. For more information, please follow other related articles on the PHP Chinese website!