python字符串按单词反转输出
方法1
import re astring = 'hello world' revwords = ' '.join(reversed(astring.split())) print(revwords)
方法2
import re astring = 'hello world' revwords = ''.join(reversed(re.split(r'(\s+)', astring))) print(revwords)
python字符串按单词反转输出
方法1
import re astring = 'hello world' revwords = ' '.join(reversed(astring.split())) print(revwords)
方法2
import re astring = 'hello world' revwords = ''.join(reversed(re.split(r'(\s+)', astring))) print(revwords)