user6882757
user6882757

Reputation:

How to print from the list dynamically

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

Answers (1)

modesitt
modesitt

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

Related Questions