文字列を特定の文字に戻すにはどうすればよいですか?文字列内の特定の部分文字列の前後のすべてを取得する方法は?
def get_header(s):
'''(str) -> str
Return the start of the given string upto and including
</head>.'''
return (s.split('</head>')[0])
これは私がやったことですが、私は「」<「/頭の前にすべてを取得する方法を知らない」>「」と、それを含みます。例えば
:
s ="hello python world </head> , i'm a beginner "
get_header(s)
これはあなたのコードは動作するはずですが、"</head>"
は含まれませんので、ちょうど最後にそれを追加
"hello python world "<"/head">" #without the quotient marks around the <
サンプル入力と期待される出力を投稿します。 –