Why does it confuse you?
It would be possible to do what you wanted, but you'd have to make more use of
1. Those functions allow any arbitrary Python expression to be entered in a string. So, if data came in from a user, that could present a security risk (in the same way that SQL injection does).
2. You'd end up having a lot of code written in the strings you pass to those functions. That's quickly going to become unreadable as you'll lose the benefits of syntax highlighting in your editor/IDE, not to mention that you'll have lots of concatenation which you won't if you're just writing Python code in the file.
It would be possible to do what you wanted, but you'd have to make more use of
exec
(or eval
, I guess). What are the problems with that? There are at least two:1. Those functions allow any arbitrary Python expression to be entered in a string. So, if data came in from a user, that could present a security risk (in the same way that SQL injection does).
2. You'd end up having a lot of code written in the strings you pass to those functions. That's quickly going to become unreadable as you'll lose the benefits of syntax highlighting in your editor/IDE, not to mention that you'll have lots of concatenation which you won't if you're just writing Python code in the file.