How to assign value from varibles to the enties of list

Question:

I have the following python code:

a = 2
b = 3
c = 1

command = ['entry1', 'entry2=', 'entry3=', 'entry4=']

I would like to assign the values of varibles a, b,c to entry2, entry3, entry4 respectively. So, command[1] needs to return entr2=2, command[2] entry3=3, command[3] entry4=1 respectively.

Could someone please assist me on how to implement this.

Asked By: ranjith

||

Answers:

Use string formatting:

command = ['entry1', f'entry2={a}', f'entry3={b}', f'entry4={c}']
Answered By: Barmar
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.