⚡️Calculator made with just one line python code
✨ Hello everyone, I hope you all are doing well. I came across a python function called eval(). In short, this is a function which evaluates expressions dynamically. That means it can calculate mathematical expressions and outputs the result. Let’s see a little bit about this function.
👨🏻🏫 Python’s eval() allows you to evaluate arbitrary Python expressions from a string-based or compiled-code-based input. This function can be handy when you’re trying to dynamically evaluate Python expressions from any input that comes as a string or a compiled code object. Here are some examples:
eval("2 ** 8")
256
eval("1024 + 1024")
2048
eval("sum([8, 16, 32])")
56
x = 100
eval("x * 2")
200
👨🏻💻 According to the reel, I am directly printing the result of the eval function in which I am providing as expression as input. So suppose if we provide ‘5 + 6 - 2 * 3 / 3’, the output will be 9. So that’s the case.
⚔️ So basically, that’s the thing. Try it and understand how it works.
❔Thoughts? Comment below.
—-------------------------------------------
If you found this useful, subscribe to this
Channel
—-------------------------------------------
🏷 #python #pythoncode #pythonprojects