非常接近this question(但不是重复的IMHO)
In [1]: def foo():
...: A = 'something' + ' ' + 'good'
...: B = 'is'
...: C = f'{B} going on'
...: return A + C
...:
In [2]: foo.__code__.co_consts
Out[2]: (None, 'something good', 'is', ' going on')
我能以某种方式帮助Python将格式化的字符串作为常量求值吗?
由于运行库能够计算字符串连接(从计算'something good'
可以明显看出),我很好奇为什么它不能将格式化的字符串计算为'is going on'