共計 253 個字符,預計需要花費 1 分鐘才能閱讀完成。
在 Python 中,可以使用 find()
方法來查找字符串中某個字符的索引位置。示例如下:
s = "Hello, World!"
char = "o"
index = s.find(char)
if index != -1:
print(f"Found '{char}' at index {index}")
else:
print(f"'{char}' not found")
這段代碼將在字符串 s
中查找字符o
,并輸出找到的索引位置。如果字符不存在,則輸出'o' not found
。
丸趣 TV 網 – 提供最優(yōu)質的資源集合!
正文完