> mystr = '''It's a "string"''' >-6ren">
gpt4 book ai didi

python - 如果它有 "and ',我如何读取这个字符串? Python

转载 作者:太空宇宙 更新时间:2023-11-04 15:09:18 24 4
gpt4 key购买 nike

我有这个基本上是一些 html 的字符串

<acronym class="non-experimental-qualifier" title="Indicates that the information given is not based on experimental findings." onclick="dialog('non_experimental_qualifiers'); Event.stop(event || window.event); return false" onmousedown="Event.stop(event || window.event);">By similarity</acronym>. <a class="attribution" href="http://hamap.expasy.org/unirule/

无论如何我可以在 python 中将其作为字符串读取。 . .通常它只有一种类型的 ' 或 "所以我只能用另一种来串起来但是......这两者都有

我怎样才能把它变成一个字符串?喜欢:

html = '<acronym class="non-experimental-qualifier" title="Indicates that the information given is not based on experimental findings." onclick="dialog('non_experimental_qualifiers'); Event.stop(event || window.event); return false" onmousedown="Event.stop(event || window.event);">By similarity</acronym>. <a class="attribution" href="http://hamap.expasy.org/unirule/'

最佳答案

您可以使用 triple-quoted string :

html = '''<acronym class="non-experimental-qualifier" title="Indicates that the information given is not based on experimental findings." onclick="dialog('non_experimental_qualifiers'); Event.stop(event || window.event); return false" onmousedown="Event.stop(event || window.event);">By similarity</acronym>. <a class="attribution" href="http://hamap.expasy.org/unirule/'''

下面是一个演示:

>>> mystr = '''It's a "string"'''
>>> mystr
'It\'s a "string"'
>>>

关于python - 如果它有 "and ',我如何读取这个字符串? Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21959633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com