l = ['a', 'b']
Вывод> the elements in list are '%a','%b'
the elements in list are '%a','%b'
l = ['a', 'b', 'c']
Вывод> the elements in list are '%a','%b','%c'
the elements in list are '%a','%b','%c'
Как и для любого количества элементов, нам нужно добавить the elements in the list are, а также express с процентом %
the elements in the list are
%
Вы можете использовать f-strings и join.
f-strings
join
sub_str = ", ".join(f"'%{e}'" for e in l) print(f"the elements in the list are {sub_str}")