如下所示:
#!/usr/bin/python # -*- coding: utf-8 -*- def rever(sentence): newwords = [] words = sentence.split() words.reverse() space = ' '#单词之间一个间隔 for word in words: newword = [] new = ''#单词的字母间无间隔 l = len(word) for i in range(l): newword.append(word[l-i-1]) neww = new.join(newword) newwords.append(neww) print space.join(newwords) rever('what\'s your problem man "htmlcode">? nam melborp ruoy s'tahw以上这篇Python给定一个句子倒序输出单词以及字母的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。