Portál AbcLinuxu, 14. července 2025 02:05
Ahoj, potrebuju ubastlit script kterej me bude do textu pridavat cislo 1 2 3 atp... takze
for pocitadlo in range(1,10):
print("text1",pocitadlo,"text2")
vysledek je:
text1 1 text2
text1 2 text2
text1 3 text2
text1 4 text2
text1 5 text2
text1 6 text2
text1 7 text2
text1 8 text2
text1 9 text2
ale ja bych potreboval aby byl:
text11text2
text12text2
text13text2
text14text2
text15text2
text16text2
text17text2
text18text2
text19text2
Řešení dotazu:
for pocitadlo in range(1,10): print("text1%dtext2" % pocitadlo)
for pocitadlo in range(1,10): print "text1{0}text2".format(pocitadlo)
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.