[英]Python: handling a large string value - if statement not working properly?
我有一個很大的字符串值,大約有 500 個字符,稱為“strPage6”,我想看看這個字符串的第 n 個位置是否具有帶有 if 語句的“%”值,但沒有成功。
#see if 330th character has value '%'
if (strPage6[330:331]=="%"):
print("330th character is '%' ")
print(strPage6)
else:
print("330th character is NOT '%' ")
print(strPage6)
我的終端返回以下值:
330th character is NOT '%'
b'%'
我嘗試將字節字符串轉換為帶有 'decode' 的普通字符串,結果如下:
strPage6=strPage.decode('utf-8')
[...]
330th character is NOT '%'
e
基本上,我希望得到以下結果:
330th character is '%'
%
感謝您的幫助!
你試過 strPage6[330]==b"%" 嗎? – 凱爾伍德
方程是否正確
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.