Reputation:
l = ['a','b']
Output > the elements in list are '%a','%b'
l = ['a','b','c']
Output > the elements in list are '%a','%b','%c'
Like for any number of elements we need to add the elements in the list are
and also with express with percentage %
Upvotes: 0
Views: 107
Reputation: 7210
You can use f-strings
and join
.
sub_str = ", ".join(f"'%{e}'" for e in l)
print(f"the elements in the list are {sub_str}")
Upvotes: 3