【发布时间】:2017-02-18 02:46:49
【问题描述】:
我有这样的代码:
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")
输出是:
g
f
@
e
d
!
c
b
a
但我想将这些单独的字符组合起来,并希望输出如下:
gf@ed!cba
【问题讨论】:
-
将
return text[::-1]简单地用作reverse函数会更容易,除非这是家庭作业或其他事情 -
一个设计为
return的函数通常不包含print语句。返回一个字符串。让函数的用户决定是否要打印返回值。
标签: python