[英]How can i remove every character before a specific character in a tuple of lists of strings in Python
[英]how to remove a specific character from a tuple using python
我有一個元組:
tuple = ('one', ('two', 'three'))
我想打印從這個元組中刪除'
以便我可以將它打印為(one, (two, three))
。
我試過這個
tuple = str(tuple)
print tuple.strip(')
但我收到此錯誤:
print tuple.strip(')
^
SyntaxError: EOL while scanning string literal
如何將我的元組轉換為所需的字符串?
t = ('one', ('two', 'three'))
t2 = str(t)
print(t2.replace("'",""))
使用像tuple
這樣的關鍵字作為變量名被認為是不好的做法,你可能會遇到麻煩。
您可以使用替換打印:
print(str(tuple).replace("'", ''))
輸出
(one, (two, three))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.