如何在python中合并两个字符串? [英] How to merge two strings in python?
本文介绍了如何在python中合并两个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将字符串合并在一起以创建一个字符串。例如,需要组合的 hello字符串为:
[H ----],[-E ---],[-LL-]和[---- O]
I need to merge strings together to create one string. For example the strings for "hello" that need to be combined are: [H----], [-E---], [--LL-], and [----O]
这是我必须使字母首位显示的当前代码。
This is the current code I have to make the letters appear in the first place.
display_string = "[" + "".join([x if x == letter else "-" for x in word]) + "]"
我该如何制作诸如
之类的字符串[H ----],[HE ---],[HELL-],最后[HELLO]?
How would I go about making strings such as [H----], [HE---], [HELL-], and finally [HELLO]?
推荐答案
s = "[H----], [-E---], [--LL-], [----O]"
print(''.join(re.findall(r'\w', s)))
HELLO
这篇关于如何在python中合并两个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文