I have code like this:
def reverse(text):
l=len(text)
while ((l-1)!=0):
print (str(text[l-1]))
l=l-1
print (str(text[0]))
a=reverse("abc!de@fg")
The output is:
g
f
@
e
d
!
c
b
a
but I want to combine these individual characters and want out put like this:
gf@ed!cba
To print without the newline at the end of each line do:
print('text', end='')
To take a list of characters and make them one string, do:
''.join(list_of_characters)
def reverse(text):
if len(text) <= 1:
return text
return reverse(text[1:]) + text[0]
print (reverse('abc!de@fg'))
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