text = 'PYTHON'
for index in range(len(text)):
print(*text[:index + 1])
The * in the print function is producing a space between the characters on sys.stdout. Can someone please tell me what is it called and what does it actually do?
The print of * for a text is equal as printing print(text[0], text[1], ..., text[n]) and this is printing each part with a space between.
you can do
text = 'PYTHON'
for index in range(len(text))
print("".join(list(text)[:index + 1]))
or
text = 'PYTHON'
for index in range(len(text))
print(*text[:index + 1], sep='')
that will print each part without space in between. Output
P
PY
PYT
PYTH
PYTHO
PYTHON
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With