Is there a way to execute the Python code stored in the form of a string?

Asked 2 years ago, Updated 2 years ago, 74 views

Is there a way to execute the Python code stored in the form of a string?

I thought my friend told me I could do it, but I didn't listen because I thought I didn't need it ㅜ<

Please tell me how to use it

string python exec

2022-09-22 13:34

1 Answers

exec()eval()보다는 좀 더 넓은 범위입니다.

For example,

exec("a = 3")
exec("a is 3")

#Same
a = 3
a is 3
a = 3
eval ("a is 3") #expression

eval ("a = 3") #assignment

You can use it appropriately depending on the situation.


2022-09-22 13:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.