Get the App
SLTechnology News&Howtos  ›  Development  › 

How to evaluate Python expressions

Shulou Source: shulou.com Published: 2022-06-01 04:23:49 09月22日 Update

This article is about how to evaluate Python expressions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Evaluate Python expressions

We all know the eval function, but do we know the literal_eval function? Maybe a lot of people don't know. You can do this:

Import ast my_list = ast.literal_eval (expr)

Instead of doing the following:

Expr = "[1,2,3]" my_list = eval (expr)

I believe this is the first time this form has been seen for most people, but in fact it has been around in Python for a long time.

Thank you for reading! This is the end of the article on "how to evaluate Python expressions". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Expression content function more article good practical practical actually form article look knowledge first time several people long time reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information NVidia Docker Shulou Tech Info