[英]What is the easiest way to concatenate string list with number array in python
[英]What is the easiest way to get a list of the keywords in a string?
例如:
str = 'abc{text}ghi{num}'
那我可以做
print(str.format(text='def',num=5))
> abcdefghi5
我想做点什么
print(str.keywords) # function does not exist
> ['text','num']
最简单的方法是什么? 我可以逐个字符地搜索{
和}
但我想知道是否有内置的python函数?
谢谢。
>>> import string
>>> text = 'abc{text}ghi{num}'
>>> [t[1] for t in string.Formatter().parse(text)]
['text', 'num']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.