python------逆序输出

------请用Python3.x
输入一行字符串,然后对其进行如下处理。

输入格式:

字符串中的元素以空格或者多个空格分隔。

输出格式:

逆序输出字符串中的所有元素。
然后输出原列表。
然后逆序输出原列表每个元素,中间以1个空格分隔。注意:最后一个元素后面不能有空格。

输入样例:

a b c e f gh
输出样例:

ghfecba
['a', 'b', 'c', 'e', 'f', 'gh']
gh f e c b a

s= str(input("请输入字符串s=")) #输入a b c e f gh
s1=s.split(" ")
print(s1)   #打印['a', 'b', 'c', 'e', 'f', 'gh']
print(''.join(s1)[::-1])  #打印 hgfecba
print(' '.join(s1)[::-1]) #打印 hg f e c b a

在python 3.5运行完全满足题的要求。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-05-10
a = input().split()
a.reverse()

相似回答