def proc1(b: str) -> str:
return 'A' + b
def proc2(b: str) -> str:
return f'A{b}'
dis.dis(proc1)
# 2 0 LOAD_CONST 1 ('A')
# 2 LOAD_FAST 0 (b)
# 4 BINARY_ADD
# 6 RETURN_VALUE
dis.dis(proc2)
# 5 0 LOAD_CONST 1 ('A')
# 2 LOAD_FAST 0 (b)
# 4 FORMAT_VALUE 0
# 6 BUILD_STRING 2
# 8 RETURN_VALUE
%timeit proc1('b')
# 72.7 ns ± 0.688 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
%timeit proc2('b')
# 74.6 ns ± 0.689 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
Первый вариант немного выгоднее