社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

删除python中的双引号

iam supreeth • 6 年前 • 1755 次点击  

我正在使用列表格式 ['Test']

我要把它藏起来 ('Test')

我试过:

test = '(' +test[0]+ ')'

输出:

'(Test)'

我试过:

test = "('"+"', '".join(test)+"')"

我得到的结果是:

"('Test')"

删除python中的双引号。我需要像 (测试) . 但现在我变得这样了``

提前谢谢

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43961
文章 [ 2 ]  |  最新文章 6 年前
DirtyBit
Reply   •   1 楼
DirtyBit    7 年前

我相信这就是你想要的:

str_list = ['Test1', 'Test2', 'Test3']
# desired output:  ('Test1', 'Test2', 'Test3')

# print(tuple(str_list))
print(str(tuple(str_list)).rstrip(',)') + ')')

输出:

('Test1', 'Test2', 'Test3')
Nordle
Reply   •   2 楼
Nordle    7 年前

干得好:

string = '''"('test')"'''

print(string.strip('"'))

>>> ('test')

使用 strip 可以从字符串中删除任何字符。