Home > Software design >  Using eval in the middle of a python statement
Using eval in the middle of a python statement

Time:10-14

I want to use eval in the middle of the following python statement:

["a", "b"]   eval('[1,2].append(3)')

but because it does not return any value (it works in an "in place" manner), I cannot actually use it there and instead I receive an error of TypeError: can only concatenate list (not "NoneType") to list . Is there any way that I can fix this issue by getting return value out of eval in Python?

CodePudding user response:

You can use list concatenation instead of calling append(). It returns the new list.

["a", "b"]   eval('[1,2]   [3]')
  • Related