0
votes

Comment peut-être la méthode de formatage de chaîne dans Python utilisé pour des éléments de liste de concaténants

var = [‘a’, ‘b’, ‘c’]
sign = [‘=’, ‘:’, ‘=’]
value = [‘100’, ‘200’, ‘300’]

out = '<{0}>{1}<{2}>'.format(vari1, equal_sign, value)
print(out)
Expected output:
  a=100
  b:200
  c=300
But it is printing 
  ['a', 'b', 'c']>['=', ':', '=']<['100', '200', '300']

1 commentaires

pour i in zip (var, signe, valeur): Imprimer ("". Joindre (i)) ?


4 Réponses :


2
votes

Essayez ceci plus simple:

var = ['a', 'b', 'c']
sign = ['=', ':', '=']
value = ['100', '200', '300']
length = 3

for i in range(length):
    print(var[i], sign[i], value[i])


0 commentaires

1
votes

Vous pouvez utiliser zip

ex: xxx

Sortie: xxx


0 commentaires

1
votes

Essayez ceci:

>>> var
['a', 'b', 'c']
>>> sign
['=', ':', '=']
>>> value
['100', '200', '300']
>>> print('\n'.join(''.join(x) for x in zip(var, sign, value)))
a=100
b:200
c=300


0 commentaires

1
votes

Utilisation de la chaîne Format:

for i in range(len(var)):
    print('{}{}{}'.format(var[i],sign[i],value[i]))


0 commentaires