One of #Python's most controversial built-in functions is `eval()`. The main reason it is controversial is that it can be used to execute arbitrary code.
The arguments for `eval()` are a string and optional globals and locals. If provided, globals must be a dictionary. If provided, locals can be any mapping object.
Here is an example:
You can use `eval()` to evaluate/execute the arbitrary code objects that you get when you run Python's `compile()` function.
The `eval()` built-in is closely related to the `exec()` built-in. `exec()` will take a code block while `eval()` only takes a single expression
I hope you enjoyed learning a little about `eval()` with me. Be sure to use it wisely and only with input that you have complete control over.!
โข โข โข
Missing some Tweet in this thread? You can try to
force a refresh
A bytearray in #Python takes the following optional arguments:
๐ source[optional]: Initializes the array of bytes
๐ encoding[optional]: Encoding of the string
๐ errors[optional]: Takes action when encoding fails
It is often useful to see an unfamiliar concept in action. Here are two examples of creating a bytearray using different encodings and printing them out